aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2007-12-28 07:42:12 +0000
committerOwen Anderson <resistor@mac.com>2007-12-28 07:42:12 +0000
commit42f61edc6ae659202b6240932a0cedba27881605 (patch)
tree414235c296a8b7421a09e2b7710cc348be0282c6 /lib
parente1572a8f6021a47995362652ad0bde78847a926f (diff)
downloadexternal_llvm-42f61edc6ae659202b6240932a0cedba27881605.tar.gz
external_llvm-42f61edc6ae659202b6240932a0cedba27881605.tar.bz2
external_llvm-42f61edc6ae659202b6240932a0cedba27881605.zip
Repair a transform that Chris noticed a bug in. Thanks to Nicholas for pointing out my stupid mistakes when writing this patch. :-)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45384 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index fc1443a9be..de528d956a 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -4835,11 +4835,18 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
Value *A, *B;
-#if 0
- // (icmp cond (sub A B) 0) -> (icmp cond A B)
- if (CI->isNullValue() && match(Op0, m_Sub(m_Value(A), m_Value(B))))
- return new ICmpInst(I.getPredicate(), A, B);
-#endif
+ // (icmp cond (sub A B) 0) -> ...
+ if (CI->isNullValue() && match(Op0, m_Sub(m_Value(A), m_Value(B)))) {
+ // (icmp cond A B) if cond is signed or equality
+ if (CmpInst::isSigned(I.getPredicate()) || I.isEquality())
+ return new ICmpInst(I.getPredicate(), A, B);
+ // (icmp ne A B) if cond is ugt
+ else if (I.getPredicate() == ICmpInst::ICMP_UGT)
+ return new ICmpInst(ICmpInst::ICMP_NE, A, B);
+ // (icmp eq A B) if cond is ule
+ else if (I.getPredicate() == ICmpInst::ICMP_ULE)
+ return new ICmpInst(ICmpInst::ICMP_EQ, A, B);
+ }
switch (I.getPredicate()) {
default: break;