From a67519be12f4df4a0c67e4e39e24da0daac1a03d Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sat, 2 Jan 2010 16:14:56 +0000 Subject: [PATCH] Fix logic error in previous commit. The != case needs to become an or, not an and. llvm-svn: 92419 --- .../lib/Transforms/Scalar/InstructionCombining.cpp | 10 +++++++--- llvm/test/Transforms/InstCombine/or.ll | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index e208d69f7c65..50e9f24cc18f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7324,9 +7324,13 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, Constant::getNullValue(P->getType())); Value *ICIQ = Builder->CreateICmp(ICI.getPredicate(), Q, Constant::getNullValue(Q->getType())); - Instruction *And = BinaryOperator::CreateAnd(ICIP, ICIQ, ""); - And->takeName(&ICI); - return And; + Instruction *Op; + if (ICI.getPredicate() == ICmpInst::ICMP_EQ) + Op = BinaryOperator::CreateAnd(ICIP, ICIQ, ""); + else + Op = BinaryOperator::CreateOr(ICIP, ICIQ, ""); + Op->takeName(&ICI); + return Op; } break; } diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll index 33058b5334ca..44228ba357cb 100644 --- a/llvm/test/Transforms/InstCombine/or.ll +++ b/llvm/test/Transforms/InstCombine/or.ll @@ -293,3 +293,17 @@ define i1 @test28(i32 %A, i32 %B) { ; CHECK: icmp ne i32 {{.*}}, 0 ; CHECK: ret i1 } + +define i1 @test29(i32* %A, i32* %B) { + %C1 = ptrtoint i32* %A to i32 + %C2 = ptrtoint i32* %B to i32 + %D = or i32 %C1, %C2 + %E = icmp ne i32 %D, 0 + ret i1 %E +; CHECK: @test29 +; CHECK: icmp ne i32* %A, null +; CHECK: icmp ne i32* %B, null +; CHECK: or i1 +; CHECK: ret i1 +} +