From 5b6dfee28e86529030cabdc356e00b4d70747d65 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 11 May 2012 01:32:59 +0000 Subject: [PATCH] Fix a minor logic mistake transforming compares in instcombine. PR12514. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156600 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/InstCombineCompares.cpp | 2 +- test/Transforms/InstCombine/cast.ll | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index ab2987ff24c..7bbdd450f11 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -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)); } diff --git a/test/Transforms/InstCombine/cast.ll b/test/Transforms/InstCombine/cast.ll index 7cf63e8ce1f..56e5ca3ff72 100644 --- a/test/Transforms/InstCombine/cast.ll +++ b/test/Transforms/InstCombine/cast.ll @@ -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 +}