summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-05-30 15:54:32 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-05-30 15:54:32 +0000
commitfcb9926813ef9bd18bf2b3aab4ab58c6522c2c5e (patch)
tree6ad8e9a57ca6f0b0eefabe1b5e2a80d39a63e4c5 /lib/Transforms/InstCombine
parent6319c0c5203450e9d9a79cc6d57764b97d814da2 (diff)
downloadllvm-fcb9926813ef9bd18bf2b3aab4ab58c6522c2c5e.tar.gz
llvm-fcb9926813ef9bd18bf2b3aab4ab58c6522c2c5e.tar.bz2
llvm-fcb9926813ef9bd18bf2b3aab4ab58c6522c2c5e.tar.xz
PR19753: Optimize comparisons with "ashr exact" of a constanst.
Patch by suyog sarda. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209903 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCompares.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 02e8bf1013..79cd1fba85 100644
--- a/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2439,6 +2439,23 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
return new ICmpInst(I.getPredicate(), A, B);
}
+ // PR19753:
+ // (icmp (ashr exact const2, A), const1) -> icmp A, Log2(const2/const1)
+ // Cases where const1 doesn't divide const2 exactly or Quotient is not
+ // exact of log2 are handled by SimplifyICmpInst call above where we
+ // return false.
+ // TODO: Handle this for lshr exact with udiv.
+ {
+ ConstantInt *CI2;
+ if (match(Op0, m_AShr(m_ConstantInt(CI2), m_Value(A))) &&
+ (cast<BinaryOperator>(Op0)->isExact())) {
+ APInt Quotient = CI2->getValue().sdiv(CI->getValue());
+ unsigned shift = Quotient.logBase2();
+ return new ICmpInst(I.getPredicate(), A,
+ ConstantInt::get(A->getType(), shift));
+ }
+ }
+
// If we have an icmp le or icmp ge instruction, turn it into the
// appropriate icmp lt or icmp gt instruction. This allows us to rely on
// them being folded in the code below. The SimplifyICmpInst code has