From d5b3aa49acc264186efce781a0a4fb30fbfb9273 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 8 Dec 2014 18:30:43 +0000 Subject: [PATCH] InstSimplify: Try to bring back the rest of r223583 This reverts r223624 with a small tweak, hopefully this will make stage3 equivalent. llvm-svn: 223679 --- llvm/lib/Analysis/InstructionSimplify.cpp | 9 +++++++-- llvm/test/Transforms/InstSimplify/AndOrXor.ll | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 5c536aa79c48..2cf1661cfd90 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1448,8 +1448,8 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, Value *X, *Y; ICmpInst::Predicate EqPred; - if (!match(ZeroICmp, m_ICmp(EqPred, m_Value(Y), m_Zero())) && - ICmpInst::isEquality(EqPred)) + if (!match(ZeroICmp, m_ICmp(EqPred, m_Value(Y), m_Zero())) || + !ICmpInst::isEquality(EqPred)) return nullptr; ICmpInst::Predicate UnsignedPred; @@ -1476,6 +1476,11 @@ static Value *simplifyUnsignedRangeCheck(ICmpInst *ZeroICmp, return UnsignedICmp; } + // X < Y && Y == 0 --> false + if (UnsignedPred == ICmpInst::ICMP_ULT && EqPred == ICmpInst::ICMP_EQ && + IsAnd) + return getFalse(UnsignedICmp->getType()); + return nullptr; } diff --git a/llvm/test/Transforms/InstSimplify/AndOrXor.ll b/llvm/test/Transforms/InstSimplify/AndOrXor.ll index c01c53ec4e1e..ce3c2aa6af22 100644 --- a/llvm/test/Transforms/InstSimplify/AndOrXor.ll +++ b/llvm/test/Transforms/InstSimplify/AndOrXor.ll @@ -166,6 +166,15 @@ define i1 @and_icmp1(i32 %x, i32 %y) { ; CHECK: %[[cmp:.*]] = icmp ult i32 %x, %y ; CHECK: ret i1 %[[cmp]] +define i1 @and_icmp2(i32 %x, i32 %y) { + %1 = icmp ult i32 %x, %y + %2 = icmp eq i32 %y, 0 + %3 = and i1 %1, %2 + ret i1 %3 +} +; CHECK-LABEL: @and_icmp2( +; CHECK: ret i1 false + define i1 @or_icmp1(i32 %x, i32 %y) { %1 = icmp ult i32 %x, %y %2 = icmp ne i32 %y, 0