When determining if we can fold (x >> C1) << C2, the bits that we need to verify...
authorOwen Anderson <resistor@mac.com>
Thu, 23 Dec 2010 23:56:24 +0000 (23:56 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 23 Dec 2010 23:56:24 +0000 (23:56 +0000)
are not the low bits of x, but the bits that WILL be the low bits after the operation completes.

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

lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstCombine/shift.ll

index e3232a491b7c6e170dab999b669282982c4c4016..a0c5ef5338f68e054715ad84d3c43e0630f8c9c4 100644 (file)
@@ -168,8 +168,9 @@ static bool CanEvaluateShifted(Value *V, unsigned NumBits, bool isLeftShift,
     // We can always turn lshr(c1)+shl(c2) -> lshr(c3)+and(c4), but it isn't
     // profitable unless we know the and'd out bits are already zero.
     if (CI->getZExtValue() > NumBits) {
+      unsigned LowBits = CI->getZExtValue() - NumBits;
       if (MaskedValueIsZero(I->getOperand(0),
-                            APInt::getLowBitsSet(TypeWidth, NumBits)))
+                          APInt::getLowBitsSet(TypeWidth, NumBits) << LowBits))
         return true;
     }
       
index 8d1c82991fdbef857d08cd2d287d259f22e5e5d2..4f6939d6323f49e3a50ebb8c746e369f7f823cb2 100644 (file)
@@ -452,3 +452,22 @@ define i32 @test38(i32 %x) nounwind readnone {
 ; CHECK-NEXT: ret i32
 }
 
+; <rdar://problem/8756731>
+; CHECK: @test39
+define i8 @test39(i32 %a0) {
+entry:
+  %tmp4 = trunc i32 %a0 to i8
+; CHECK: and i8 %tmp49, 64
+  %tmp5 = shl i8 %tmp4, 5
+  %tmp48 = and i8 %tmp5, 32
+  %tmp49 = lshr i8 %tmp48, 5
+  %tmp50 = mul i8 %tmp49, 64
+  %tmp51 = xor i8 %tmp50, %tmp5
+; CHECK: and i8 %0, 16
+  %tmp52 = and i8 %tmp51, -128
+  %tmp53 = lshr i8 %tmp52, 7
+  %tmp54 = mul i8 %tmp53, 16
+  %tmp55 = xor i8 %tmp54, %tmp51
+; CHECK: ret i8 %tmp551
+  ret i8 %tmp55
+}