summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp32
1 files changed, 15 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 815af57fc7a..bd319ef83df 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -251,22 +251,20 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
}
}
+ if (Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
+ return FoldedMul;
+
// Simplify mul instructions with a constant RHS.
if (isa<Constant>(Op1)) {
- if (Instruction *FoldedMul = foldOpWithConstantIntoOperand(I))
- return FoldedMul;
-
// Canonicalize (X+C1)*CI -> X*CI+C1*CI.
- {
- Value *X;
- Constant *C1;
- if (match(Op0, m_OneUse(m_Add(m_Value(X), m_Constant(C1))))) {
- Value *Mul = Builder.CreateMul(C1, Op1);
- // Only go forward with the transform if C1*CI simplifies to a tidier
- // constant.
- if (!match(Mul, m_Mul(m_Value(), m_Value())))
- return BinaryOperator::CreateAdd(Builder.CreateMul(X, Op1), Mul);
- }
+ Value *X;
+ Constant *C1;
+ if (match(Op0, m_OneUse(m_Add(m_Value(X), m_Constant(C1))))) {
+ Value *Mul = Builder.CreateMul(C1, Op1);
+ // Only go forward with the transform if C1*CI simplifies to a tidier
+ // constant.
+ if (!match(Mul, m_Mul(m_Value(), m_Value())))
+ return BinaryOperator::CreateAdd(Builder.CreateMul(X, Op1), Mul);
}
}
@@ -555,11 +553,11 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
bool AllowReassociate = I.isFast();
+ if (Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I))
+ return FoldedMul;
+
// Simplify mul instructions with a constant RHS.
if (auto *C = dyn_cast<Constant>(Op1)) {
- if (Instruction *FoldedMul = foldOpWithConstantIntoOperand(I))
- return FoldedMul;
-
// -X * C --> X * -C
Value *X;
if (match(Op0, m_FNeg(m_Value(X))))
@@ -900,7 +898,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
}
if (!C2->isNullValue()) // avoid X udiv 0
- if (Instruction *FoldedDiv = foldOpWithConstantIntoOperand(I))
+ if (Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(I))
return FoldedDiv;
}
OpenPOWER on IntegriCloud