summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-12-20 16:18:51 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-12-20 16:18:51 +0000
commit68531baea926431ba4a4a94d12c99db2b444845f (patch)
tree105ee5a0d0e0bda65a82b6c65d4e0bdb0da79a14 /llvm/lib/Transforms
parentca2511d8497c1e99b29f1c7cefa736a893cb788c (diff)
downloadbcm5719-llvm-68531baea926431ba4a4a94d12c99db2b444845f.tar.gz
bcm5719-llvm-68531baea926431ba4a4a94d12c99db2b444845f.zip
Teach InstCombine to merge (icmp ult (X + CA), C1) | (icmp eq X, C2) into (icmp ult (X + CA), C1 + 1) if C2 + CA == C1.
InstCombine creates these so now we compile x == 23 || x == 24 || x == 25 to %x.off = add i32 %x, -23 %1 = icmp ult i32 %x.off, 3 instead of %x.off = add i32 %x, -23 %1 = icmp ult i32 %x.off, 2 %cmp3 = icmp eq i32 %x, 25 %ret2 = or i1 %1, %cmp3 llvm-svn: 122248
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 41734f6ac9d..57fe870158b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1450,7 +1450,16 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
}
}
-
+
+ // (icmp ult (X + CA), C1) | (icmp eq X, C2) -> (icmp ult (X + CA), C1 + 1)
+ // iff C2 + CA == C1.
+ if (LHSCC == ICmpInst::ICMP_ULT) {
+ ConstantInt *AddCst;
+ if (match(Val, m_Add(m_Specific(Val2), m_ConstantInt(AddCst))))
+ if (RHSCst->getValue() + AddCst->getValue() == LHSCst->getValue())
+ return Builder->CreateICmp(LHSCC, Val, AddOne(LHSCst));
+ }
+
// From here on, we only handle:
// (icmp1 A, C1) | (icmp2 A, C2) --> something simpler.
if (Val != Val2) return 0;
OpenPOWER on IntegriCloud