summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-05-16 16:57:04 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-05-16 16:57:04 +0000
commitea8d5dbf249dd6a8b21603794fe368bb82082ca4 (patch)
treefea6c74214828c3fc554a41025023f5a3d6bebc7 /llvm/lib
parent83c57436500fca8f09cf00e816470df46bd5ca6f (diff)
downloadbcm5719-llvm-ea8d5dbf249dd6a8b21603794fe368bb82082ca4.tar.gz
bcm5719-llvm-ea8d5dbf249dd6a8b21603794fe368bb82082ca4.zip
InstSimplify: Optimize using dividend in sdiv
Summary: The dividend in an sdiv tells us the largest and smallest possible results. Use this fact to optimize comparisons against an sdiv with a constant dividend. Reviewers: nicholas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3795 llvm-svn: 208999
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 5421a399226..4cad81b1398 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2020,6 +2020,10 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
APInt NegOne = APInt::getAllOnesValue(Width);
if (!CI2->isZero())
Upper = NegOne.udiv(CI2->getValue()) + 1;
+ } else if (match(LHS, m_SDiv(m_ConstantInt(CI2), m_Value()))) {
+ // 'sdiv CI2, x' produces [-|CI2|, |CI2|].
+ Upper = CI2->getValue().abs() + 1;
+ Lower = (-Upper) + 1;
} else if (match(LHS, m_SDiv(m_Value(), m_ConstantInt(CI2)))) {
// 'sdiv x, CI2' produces [INT_MIN / CI2, INT_MAX / CI2].
APInt IntMin = APInt::getSignedMinValue(Width);
OpenPOWER on IntegriCloud