aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAddSub.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 9b72eb924a..c04a6b2a62 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -675,6 +675,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
C2);
return BinaryOperator::CreateMul(Op0, CP1);
}
+
+ // X - A*-B -> X + A*B
+ // X - -A*B -> X + A*B
+ Value *A, *B;
+ if (match(Op1I, m_Mul(m_Value(A), m_Neg(m_Value(B)))) ||
+ match(Op1I, m_Mul(m_Neg(m_Value(A)), m_Value(B)))) {
+ Value *NewMul = Builder->CreateMul(A, B);
+ return BinaryOperator::CreateAdd(Op0, NewMul);
+ }
}
}