Fix a miscompilation from Dan's recent apintification.
authorChris Lattner <sabre@nondot.org>
Thu, 14 Feb 2008 18:48:56 +0000 (18:48 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 14 Feb 2008 18:48:56 +0000 (18:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47128 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
test/CodeGen/X86/2008-02-14-BitMiscompile.ll [new file with mode: 0644]

index 76cf425499e4e5351af6997c7533f8a186b36a14..f8e1fea679c68a4df03bea5476867556dfe50a4c 100644 (file)
@@ -1437,12 +1437,10 @@ void SelectionDAG::ComputeMaskedBits(SDOperand Op, const APInt &Mask,
     // We know that the top bits of C-X are clear if X contains less bits
     // than C (i.e. no wrap-around can happen).  For example, 20-X is
     // positive if we can prove that X is >= 0 and < 16.
-
-    // sign bit clear
     if (CLHS->getAPIntValue().isNonNegative()) {
       unsigned NLZ = (CLHS->getAPIntValue()+1).countLeadingZeros();
       // NLZ can't be BitWidth with no sign bit
-      APInt MaskV = APInt::getHighBitsSet(BitWidth, NLZ);
+      APInt MaskV = APInt::getHighBitsSet(BitWidth, NLZ+1);
       ComputeMaskedBits(Op.getOperand(1), MaskV, KnownZero, KnownOne, Depth+1);
 
       // If all of the MaskV bits are known to be zero, then we know the output
diff --git a/test/CodeGen/X86/2008-02-14-BitMiscompile.ll b/test/CodeGen/X86/2008-02-14-BitMiscompile.ll
new file mode 100644 (file)
index 0000000..5bf8456
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep and
+define i32 @test(i1 %A) {
+       %B = zext i1 %A to i32          ; <i32> [#uses=1]
+       %C = sub i32 0, %B              ; <i32> [#uses=1]
+       %D = and i32 %C, 255            ; <i32> [#uses=1]
+       ret i32 %D
+}
+