summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-10-26 19:18:43 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-10-26 19:18:43 +0000
commit01969218a4c33884460ac911cca3280bb184a344 (patch)
tree924d68f86bef2386f8cfb243caf0d7ee4b42255f /llvm/lib/Analysis
parent4447d7a8165fd5020f384341dd069a05b5206980 (diff)
downloadbcm5719-llvm-01969218a4c33884460ac911cca3280bb184a344.tar.gz
bcm5719-llvm-01969218a4c33884460ac911cca3280bb184a344.zip
Simplify `x >=u x >> y` and `x >=u x udiv y`
Summary: Extends InstSimplify to handle both `x >=u x >> y` and `x >=u x udiv y`. This is a folloup of rL258422 and https://github.com/rust-lang/rust/pull/30917 where llvm failed to optimize away the bounds checking in a binary search. Patch by Arthur Silva! Reviewers: sanjoy Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25941 llvm-svn: 285228
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 1679d3a4667..398ac52c39c 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2857,6 +2857,17 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
return getTrue(ITy);
}
+ // x >=u x >> y
+ // x >=u x udiv y.
+ if (RBO && (match(RBO, m_LShr(m_Specific(LHS), m_Value())) ||
+ match(RBO, m_UDiv(m_Specific(LHS), m_Value())))) {
+ // icmp pred X, (X op Y)
+ if (Pred == ICmpInst::ICMP_ULT)
+ return getFalse(ITy);
+ if (Pred == ICmpInst::ICMP_UGE)
+ return getTrue(ITy);
+ }
+
// handle:
// CI2 << X == CI
// CI2 << X != CI
OpenPOWER on IntegriCloud