diff options
author | Chen Zheng <czhengsz@cn.ibm.com> | 2019-01-01 01:09:20 +0000 |
---|---|---|
committer | Chen Zheng <czhengsz@cn.ibm.com> | 2019-01-01 01:09:20 +0000 |
commit | 4952e668f8e525820bb59ea78c1e5eeea3da68fe (patch) | |
tree | 350c039f660453b815d467a7496646b365d06d02 /llvm/lib | |
parent | 745983ba0ed8a2a8bbd8b75beaa9f3a4a02dad95 (diff) | |
download | bcm5719-llvm-4952e668f8e525820bb59ea78c1e5eeea3da68fe.tar.gz bcm5719-llvm-4952e668f8e525820bb59ea78c1e5eeea3da68fe.zip |
[InstCombine] canonicalize MUL with NEG operand
-X * Y --> -(X * Y)
X * -Y --> -(X * Y)
Differential Revision: https://reviews.llvm.org/D55961
llvm-svn: 350185
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index c348aecb2d4..7e99f3e4e50 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -244,6 +244,11 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { return NewMul; } + // -X * Y --> -(X * Y) + // X * -Y --> -(X * Y) + if (match(&I, m_c_Mul(m_OneUse(m_Neg(m_Value(X))), m_Value(Y)))) + return BinaryOperator::CreateNeg(Builder.CreateMul(X, Y)); + // (X / Y) * Y = X - (X % Y) // (X / Y) * -Y = (X % Y) - X { |