Teach instcombine propagate zeroness through shl instructions, implementing
authorChris Lattner <sabre@nondot.org>
Fri, 6 May 2005 04:53:20 +0000 (04:53 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 6 May 2005 04:53:20 +0000 (04:53 +0000)
and.ll:test31

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21717 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 6cc7bbe3dc7b9cba614c734085ef0edd69cd6ea0..51141162bfb8c7f9c76a5da268d09db0c673fba0 100644 (file)
@@ -1361,14 +1361,10 @@ static bool MaskedValueIsZero(Value *V, ConstantIntegral *Mask) {
       break;
     }
     case Instruction::Shl:
-      // (shl X, C1) & C2 == 0   iff  (-1 << C1) & C2 == 0
-      if (ConstantUInt *SA = dyn_cast<ConstantUInt>(I->getOperand(1))) {
-        Constant *C1 = ConstantIntegral::getAllOnesValue(I->getType());
-        C1 = ConstantExpr::getShl(C1, SA);
-        C1 = ConstantExpr::getAnd(C1, Mask);
-        if (C1->isNullValue())
-          return true;
-      }
+      // (shl X, C1) & C2 == 0   iff   (X & C2 >>u C1) == 0
+      if (ConstantUInt *SA = dyn_cast<ConstantUInt>(I->getOperand(1)))
+        return MaskedValueIsZero(I->getOperand(0),
+                      cast<ConstantIntegral>(ConstantExpr::getUShr(Mask, SA)));
       break;
     case Instruction::Shr:
       // (ushr X, C1) & C2 == 0   iff  (-1 >> C1) & C2 == 0