diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-05-15 00:02:20 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-05-15 00:02:20 +0000 |
commit | 186c94244c96b25bf4cd4924dc1db335d849e5c9 (patch) | |
tree | f387cf98c0f46eb530ca36e2955f1dcdf5cb2eeb /llvm/lib/Transforms | |
parent | ceae1fbafd13b67cf0c6d5d784ada87455fd9a2f (diff) | |
download | bcm5719-llvm-186c94244c96b25bf4cd4924dc1db335d849e5c9.tar.gz bcm5719-llvm-186c94244c96b25bf4cd4924dc1db335d849e5c9.zip |
InstCombine: Optimize -x s< cst
Summary:
This gets rid of a sub instruction by moving the negation to the
constant when valid.
Reviewers: nicholas
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D3773
llvm-svn: 208827
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9424ad2b853..02e8bf10135 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2971,6 +2971,16 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { BO0->hasOneUse() && BO1->hasOneUse()) return new ICmpInst(Pred, D, B); + // icmp (0-X) < cst --> x > -cst + if (NoOp0WrapProblem && ICmpInst::isSigned(Pred)) { + Value *X; + if (match(BO0, m_Neg(m_Value(X)))) + if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) + if (!RHSC->isMinValue(/*isSigned=*/true)) + return new ICmpInst(I.getSwappedPredicate(), X, + ConstantExpr::getNeg(RHSC)); + } + BinaryOperator *SRem = nullptr; // icmp (srem X, Y), Y if (BO0 && BO0->getOpcode() == Instruction::SRem && |