Fix a minor logic mistake transforming compares in instcombine. PR12514.
authorEli Friedman <eli.friedman@gmail.com>
Fri, 11 May 2012 01:32:59 +0000 (01:32 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 11 May 2012 01:32:59 +0000 (01:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156600 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/cast.ll

index ab2987ff24cddd8df89622aebe52da42a447fbb4..7bbdd450f111bf2fe33c3545f62e7117b61f3a08 100644 (file)
@@ -1035,7 +1035,7 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
       if ((KnownZero|KnownOne).countLeadingOnes() >= SrcBits-DstBits) {
         // Pull in the high bits from known-ones set.
         APInt NewRHS = RHS->getValue().zext(SrcBits);
-        NewRHS |= KnownOne;
+        NewRHS |= KnownOne & APInt::getHighBitsSet(SrcBits, SrcBits-DstBits);
         return new ICmpInst(ICI.getPredicate(), LHSI->getOperand(0),
                             ConstantInt::get(ICI.getContext(), NewRHS));
       }
index 7cf63e8ce1f1cb55f0d968d65cabb5a62ed03b36..56e5ca3ff7209af9f0ff8447209a9b9db6b503fc 100644 (file)
@@ -679,3 +679,18 @@ define i64 @test_mmx_const(<2 x i32> %c) nounwind {
 ; CHECK: @test_mmx_const
 ; CHECK-NOT: x86_mmx
 }
+
+; PR12514
+define i1 @test67(i1 %a, i32 %b) {
+  %tmp2 = zext i1 %a to i32
+  %conv6 = xor i32 %tmp2, 1
+  %and = and i32 %b, %conv6
+  %sext = shl nuw nsw i32 %and, 24
+  %neg.i = xor i32 %sext, -16777216
+  %conv.i.i = ashr exact i32 %neg.i, 24
+  %trunc = trunc i32 %conv.i.i to i8
+  %tobool.i = icmp eq i8 %trunc, 0
+  ret i1 %tobool.i
+; CHECK: @test67
+; CHECK: ret i1 false
+}