[llvm] [InstCombine] Remove mul of SPF abs fold (PR #88675)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 02:24:27 PDT 2024


================
@@ -319,19 +319,12 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
   }
 
   // abs(X) * abs(X) -> X * X
-  // nabs(X) * nabs(X) -> X * X
-  if (Op0 == Op1) {
-    Value *X, *Y;
-    SelectPatternFlavor SPF = matchSelectPattern(Op0, X, Y).Flavor;
-    if (SPF == SPF_ABS || SPF == SPF_NABS)
-      return BinaryOperator::CreateMul(X, X);
-
-    if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X))))
-      return BinaryOperator::CreateMul(X, X);
-  }
+  Value *X;
+  if (Op0 == Op1 && match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X))))
+    return BinaryOperator::CreateMul(X, X);
----------------
dtcxzyw wrote:

We can propagate nsw flag as the following code does.
Alive2: https://alive2.llvm.org/ce/z/uQpZJJ

FYI this pattern is rare: https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/home/dtcxzyw/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp.html#L321

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


More information about the llvm-commits mailing list