diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-01-21 18:55:54 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-01-21 18:55:54 +0000 |
commit | 3af5bf30e33f8a7ca5929de0b2821190206f3999 (patch) | |
tree | 930bcf8b47b069470c0e3be5ccc095a011428676 /llvm/lib | |
parent | 406808e344ab4f1c581979314b05285c37afe072 (diff) | |
download | bcm5719-llvm-3af5bf30e33f8a7ca5929de0b2821190206f3999.tar.gz bcm5719-llvm-3af5bf30e33f8a7ca5929de0b2821190206f3999.zip |
[InstCombine] Simplify (x >> y) <= x
This commit extends the patterns recognised by InstSimplify to also handle (x >> y) <= x in the same way as (x /u y) <= x.
The missing optimisation was found investigating why LLVM did not optimise away bound checks in a binary search: https://github.com/rust-lang/rust/pull/30917
Patch by Andrea Canciani!
Differential Revision: http://reviews.llvm.org/D16402
llvm-svn: 258422
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 2b577f0342b..1300ec9560c 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2727,9 +2727,11 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, } } + // x >> y <=u x // x udiv y <=u x. - if (LBO && match(LBO, m_UDiv(m_Specific(RHS), m_Value()))) { - // icmp pred (X /u Y), X + if (LBO && (match(LBO, m_LShr(m_Specific(RHS), m_Value())) || + match(LBO, m_UDiv(m_Specific(RHS), m_Value())))) { + // icmp pred (X op Y), X if (Pred == ICmpInst::ICMP_UGT) return getFalse(ITy); if (Pred == ICmpInst::ICMP_ULE) |