summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-05-14 20:16:28 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-05-14 20:16:28 +0000
commitcd237ed5853bda1dab27323236119e4342a19860 (patch)
treeae30d37e6dbf9018ec09943c2628b04a3c861973 /lib/Analysis
parente0776de2df9c47af5002cbc04354b52f3a1ee9b3 (diff)
downloadllvm-cd237ed5853bda1dab27323236119e4342a19860.tar.gz
llvm-cd237ed5853bda1dab27323236119e4342a19860.tar.bz2
llvm-cd237ed5853bda1dab27323236119e4342a19860.tar.xz
InstSimplify: Optimize signed icmp of -(zext V)
Summary: We know that -(zext V) will always be <= zero, simplify signed icmps that have these. Uncovered using http://www.cs.utah.edu/~regehr/souper/ Reviewers: nicholas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3754 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 4c621b0e91..5421a39922 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -2280,6 +2280,28 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
}
}
+ // 0 - (zext X) pred C
+ if (!CmpInst::isUnsigned(Pred) && match(LHS, m_Neg(m_ZExt(m_Value())))) {
+ if (ConstantInt *RHSC = dyn_cast<ConstantInt>(RHS)) {
+ if (RHSC->getValue().isStrictlyPositive()) {
+ if (Pred == ICmpInst::ICMP_SLT)
+ return ConstantInt::getTrue(RHSC->getContext());
+ if (Pred == ICmpInst::ICMP_SGE)
+ return ConstantInt::getFalse(RHSC->getContext());
+ if (Pred == ICmpInst::ICMP_EQ)
+ return ConstantInt::getFalse(RHSC->getContext());
+ if (Pred == ICmpInst::ICMP_NE)
+ return ConstantInt::getTrue(RHSC->getContext());
+ }
+ if (RHSC->getValue().isNonNegative()) {
+ if (Pred == ICmpInst::ICMP_SLE)
+ return ConstantInt::getTrue(RHSC->getContext());
+ if (Pred == ICmpInst::ICMP_SGT)
+ return ConstantInt::getFalse(RHSC->getContext());
+ }
+ }
+ }
+
// icmp pred (urem X, Y), Y
if (LBO && match(LBO, m_URem(m_Value(), m_Specific(RHS)))) {
bool KnownNonNegative, KnownNegative;