[llvm] [InstCombine] Simplifiy `(-x * y * -x)` into `(x * y * x)` (PR #72953)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 08:53:59 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_Mul(m_c_Mul(m_Value(Y), m_Neg(m_Value(X))),
+                      m_Neg(m_Deferred(X))))) {
----------------
nikic wrote:

This will be a regression if the inner mul has multiple uses. Please add a multi-use test.

https://github.com/llvm/llvm-project/pull/72953


More information about the llvm-commits mailing list