[llvm] [InstCombine] Fold abs(a * abs(b)) --> abs(a * b) (PR #78110)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 16:23:08 PST 2024


================
@@ -218,6 +218,17 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
                   : BinaryOperator::CreateNeg(Op0);
   }
 
+  {
+    // abs(a * abs(b)) --> abs(a * b)
+    Value *A, *B;
+    if (match(&I, m_OneUse(m_c_Mul(m_Value(A),
+                                   m_Intrinsic<Intrinsic::abs>(m_Value(B)))))) {
+      Value *New =
+          HasNSW ? Builder.CreateNSWMul(A, B) : Builder.CreateMul(A, B);
----------------
elhewaty wrote:

@dtcxzyw  I will update the patch now, and is the way that I used ` thwart complexity-based canonicalization` correct?

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


More information about the llvm-commits mailing list