Specifically, this is done near the end of "SimplifyICmpInst" using
computeKnownBits() as the broader solution. There are even vector
tests (yay!) for this in test/Transforms/InstSimplify/compare.ll.
I considered putting an assert here instead of just deleting, but
then we could assert every possible fold in InstSimplify in
InstCombine, so...less is more?
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279300
91177308-0d34-0410-b5e6-
96231b3b80d8
ICmpInst::Predicate Pred = Cmp.getPredicate();
Value *X = Shl->getOperand(0);
if (Cmp.isEquality()) {
- // If we are comparing against bits always shifted out, the comparison
- // cannot succeed.
- Constant *Comp =
- ConstantExpr::getShl(ConstantExpr::getLShr(RHS, ShAmt), ShAmt);
- if (Comp != RHS) { // Comparing against a bit that we know is zero.
- bool IsICMP_NE = Pred == ICmpInst::ICMP_NE;
- Constant *Cst = Builder->getInt1(IsICMP_NE);
- return replaceInstUsesWith(Cmp, Cst);
- }
-
// If the shift is NUW, then it is just shifting out zeros, no need for an
// AND.
if (cast<BinaryOperator>(Shl)->hasNoUnsignedWrap())