Instcombine zext(trunc(x) & mask) to x&mask, even if the trunc has
multiple users.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73656 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 170b476..bf287f2 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -8564,6 +8564,20 @@
}
}
+ // zext(trunc(t) & C) -> (t & C) if C is a mask.
+ if (SrcI && SrcI->getOpcode() == Instruction::And && SrcI->hasOneUse())
+ if (ConstantInt *C = dyn_cast<ConstantInt>(SrcI->getOperand(1)))
+ if (TruncInst *TI = dyn_cast<TruncInst>(SrcI->getOperand(0))) {
+ Value *TI0 = TI->getOperand(0);
+ if (TI0->getType() == CI.getType()) {
+ unsigned TO = C->getValue().countTrailingOnes();
+ if (APIntOps::isMask(TO, C->getValue()))
+ return
+ BinaryOperator::Create(Instruction::And, TI0,
+ ConstantExpr::getZExt(C, CI.getType()));
+ }
+ }
+
return 0;
}