[llvm] [InstCombine] Simplifiy `(-x * y * -x)` into `(x * y * x)` (PR #72953)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 21 09:18:55 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) {
+ auto *Mul = BinaryOperator::CreateMul(
+ X, Builder.CreateMul(
+ X, Y, "", /*HasNUW*/ false,
+ cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap()));
----------------
goldsteinn wrote:
Think it would be cleaner to just create a second value `Value * MulXY = Builder.CreateMul(X, Y); MulXY->setHasNoSignedWrap()`
https://github.com/llvm/llvm-project/pull/72953
More information about the llvm-commits
mailing list