[llvm] [InstCombine] Simplifiy `(-x * y * -x)` into `(x * y * x)` (PR #72953)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 27 09:00:09 PST 2023
================
@@ -352,6 +352,19 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
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 * -X --> X * Y * X
+ if (match(&I, m_c_Mul(m_Neg(m_Value(X)),
+ m_c_Mul(m_Value(Y), m_Neg(m_Deferred(X)))))) {
+ if (X == Y) {
+ Value *MulXY = Builder.CreateMul(X, Y);
+ bool BO0HasNSW = cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap();
----------------
goldsteinn wrote:
Think this only works if its the `mul` that has `nsw`. `Op0` is not guranteed to be the `mul` (b.c you do commutative match above).
https://github.com/llvm/llvm-project/pull/72953
More information about the llvm-commits
mailing list