From: Chris Lattner Date: Mon, 1 Feb 2010 20:04:40 +0000 (+0000) Subject: fix PR6195, a bug constant folding scalar -> vector compares. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6304b0dd631ba65f3e325d8ed85a0f770d74d633;p=oota-llvm.git fix PR6195, a bug constant folding scalar -> vector compares. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94997 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 5e4b4720972..d537b273761 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -2017,10 +2017,12 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, return ConstantInt::get(Type::getInt1Ty(Context), Result); // If the right hand side is a bitcast, try using its inverse to simplify - // it by moving it to the left hand side. + // it by moving it to the left hand side. We can't do this if it would turn + // a vector compare into scalar compare of visa versa. if (ConstantExpr *CE2 = dyn_cast(C2)) { - if (CE2->getOpcode() == Instruction::BitCast) { - Constant *CE2Op0 = CE2->getOperand(0); + Constant *CE2Op0 = CE2->getOperand(0); + if (CE2->getOpcode() == Instruction::BitCast && + isa(CE2->getType()) ==isa(CE2Op0->getType())){ Constant *Inverse = ConstantExpr::getBitCast(C1, CE2Op0->getType()); return ConstantExpr::getICmp(pred, Inverse, CE2Op0); } diff --git a/test/Transforms/InstCombine/icmp.ll b/test/Transforms/InstCombine/icmp.ll index 79fa220752b..c2234a10e5b 100644 --- a/test/Transforms/InstCombine/icmp.ll +++ b/test/Transforms/InstCombine/icmp.ll @@ -112,3 +112,12 @@ define i1 @test11(i32 %x) { ; CHECK: ret i1 true } +; PR6195 +define i1 @test12(i1 %A) { + %S = select i1 %A, i64 -4294967295, i64 8589934591 + %B = icmp ne i64 bitcast (<2 x i32> to i64), %S + ret i1 %B +; CHECK: @test12 +; CHECK-NEXT: %B = select i1 +; CHECK-NEXT: ret i1 %B +}