Just mark the sign bit as known zero, rather than any other irrelevant bits
authorDuncan Sands <baldrick@free.fr>
Mon, 30 Apr 2012 11:56:58 +0000 (11:56 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 30 Apr 2012 11:56:58 +0000 (11:56 +0000)
known zero in the LHS.  Fixes PR12541.

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

lib/Analysis/ValueTracking.cpp
test/Transforms/InstCombine/2012-04-30-SRem.ll [new file with mode: 0644]

index a430f6281ef054329dbd6e521d0214d0a4c7cf79..1418e01d7c814c4dd200a3481f559c11bb0bdd7d 100644 (file)
@@ -564,7 +564,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne,
                         Depth+1);
       // If it's known zero, our sign bit is also zero.
       if (LHSKnownZero.isNegative())
-        KnownZero |= LHSKnownZero;
+        KnownZero.setBit(BitWidth - 1);
     }
 
     break;
diff --git a/test/Transforms/InstCombine/2012-04-30-SRem.ll b/test/Transforms/InstCombine/2012-04-30-SRem.ll
new file mode 100644 (file)
index 0000000..a285d5a
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+; PR12541
+
+define i32 @foo(i32 %x) {
+  %y = xor i32 %x, 3
+  %z = srem i32 1656690544, %y
+  %sext = shl i32 %z, 24
+  %s = ashr exact i32 %sext, 24
+  ret i32 %s
+; CHECK-NOT: and
+; The shifts were wrongly being turned into an and with 112
+}