aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/InstructionSimplify.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-06 22:05:31 +0000
committerChris Lattner <sabre@nondot.org>2011-02-06 22:05:31 +0000
commitc6ee9181a51fdfa3c07e1e53695681c55aa98ce4 (patch)
tree1b11913f91b212aa9a03e4a16ee307d609a9a7c2 /lib/Analysis/InstructionSimplify.cpp
parentc35a44d3d73a429e59fb3044ee723db0511862f2 (diff)
downloadexternal_llvm-c6ee9181a51fdfa3c07e1e53695681c55aa98ce4.zip
external_llvm-c6ee9181a51fdfa3c07e1e53695681c55aa98ce4.tar.gz
external_llvm-c6ee9181a51fdfa3c07e1e53695681c55aa98ce4.tar.bz2
teach instsimplify to transform (X / Y) * Y to X
when the div is an exact udiv. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124994 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InstructionSimplify.cpp')
-rw-r--r--lib/Analysis/InstructionSimplify.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index 220868f..7bb8f69 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -735,9 +735,11 @@ static Value *SimplifyMulInst(Value *Op0, Value *Op1, const TargetData *TD,
// (X / Y) * Y -> X if the division is exact.
Value *X = 0, *Y = 0;
if ((match(Op0, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op1) || // (X / Y) * Y
- (match(Op1, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op0)) { // Y * (X / Y)
- BinaryOperator *SDiv = cast<BinaryOperator>(Y == Op1 ? Op0 : Op1);
- if (SDiv->isExact())
+ (match(Op0, m_UDiv(m_Value(X), m_Value(Y))) && Y == Op1) ||
+ (match(Op1, m_SDiv(m_Value(X), m_Value(Y))) && Y == Op0) || // Y * (X / Y)
+ (match(Op1, m_UDiv(m_Value(X), m_Value(Y))) && Y == Op0)) {
+ BinaryOperator *Div = cast<BinaryOperator>(Y == Op1 ? Op0 : Op1);
+ if (Div->isExact())
return X;
}