summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorErik Verbruggen <erikjv@me.com>2014-03-27 11:16:05 +0000
committerErik Verbruggen <erikjv@me.com>2014-03-27 11:16:05 +0000
commit59a12198463bb13f1496205e496a2131462d3f88 (patch)
tree00762d21bc95bc44bcc1c08b9fa7213e7577d3f8 /llvm/lib/Transforms
parentd897b564ca26228fe1b0f11de5f60f1645129da8 (diff)
downloadbcm5719-llvm-59a12198463bb13f1496205e496a2131462d3f88.tar.gz
bcm5719-llvm-59a12198463bb13f1496205e496a2131462d3f88.zip
InstCombine: merge constants in both operands of icmp.
Transform: icmp X+Cst2, Cst into: icmp X, Cst-Cst2 when Cst-Cst2 does not overflow, and the add has nsw. llvm-svn: 204912
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 8c0ad525980..9bf38189542 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3008,6 +3008,19 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// icmp X, X+Cst
if (match(Op1, m_Add(m_Value(X), m_ConstantInt(Cst))) && Op0 == X)
return FoldICmpAddOpCst(I, X, Cst, I.getSwappedPredicate());
+
+ ConstantInt *Cst2;
+ if (match(Op1, m_ConstantInt(Cst)) &&
+ match(Op0, m_Add(m_Value(X), m_ConstantInt(Cst2))) &&
+ cast<BinaryOperator>(Op0)->hasNoSignedWrap()) {
+ // icmp X+Cst2, Cst --> icmp X, Cst-Cst2
+ // iff Cst-Cst2 does not overflow
+ bool Overflow;
+ APInt NewCst = Cst->getValue().ssub_ov(Cst2->getValue(), Overflow);
+ if (!Overflow)
+ return new ICmpInst(I.getPredicate(), X,
+ ConstantInt::get(Cst->getType(), NewCst));
+ }
}
return Changed ? &I : 0;
}
OpenPOWER on IntegriCloud