[llvm] ba7da14 - Revert "[InstSimplify] reduce code duplication for fmul folds; NFC"

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 08:21:43 PDT 2022


Author: Sanjay Patel
Date: 2022-10-03T11:21:23-04:00
New Revision: ba7da14d83dedc160492d9b8eb36ebd69a442a87

URL: https://github.com/llvm/llvm-project/commit/ba7da14d83dedc160492d9b8eb36ebd69a442a87
DIFF: https://github.com/llvm/llvm-project/commit/ba7da14d83dedc160492d9b8eb36ebd69a442a87.diff

LOG: Revert "[InstSimplify] reduce code duplication for fmul folds; NFC"

This reverts commit 7b7940f9da80de6aa0b8f28a0ef809dafe4cdffc.
This missed a test update.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 96b665e1c1f11..c7a16562b901f 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5325,18 +5325,22 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
   if (!isDefaultFPEnvironment(ExBehavior, Rounding))
     return nullptr;
 
-  // Canonicalize constant as operand 1.
-  if (match(Op0, m_ImmConstant()))
-    std::swap(Op0, Op1);
-
-  // X * 1.0 --> X
+  // fmul X, 1.0 ==> X
   if (match(Op1, m_FPOne()))
     return Op0;
 
-  // X * 0.0 --> 0.0 (with nnan and nsz)
+  // fmul 1.0, X ==> X
+  if (match(Op0, m_FPOne()))
+    return Op1;
+
+  // fmul nnan nsz X, 0 ==> 0
   if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op1, m_AnyZeroFP()))
     return ConstantFP::getNullValue(Op0->getType());
 
+  // fmul nnan nsz 0, X ==> 0
+  if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZeroFP()))
+    return ConstantFP::getNullValue(Op1->getType());
+
   // sqrt(X) * sqrt(X) --> X, if we can:
   // 1. Remove the intermediate rounding (reassociate).
   // 2. Ignore non-zero negative numbers because sqrt would produce NAN.

diff  --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index 1ba4045a4e308..be84594e72027 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -161,9 +161,9 @@ define <2 x float> @fadd_x_n0_vec_undef_elt(<2 x float> %a) {
   ret <2 x float> %ret
 }
 
-; fmul 1.0, X ==> X
-define double @fmul_1_X(double %a) {
-; CHECK-LABEL: @fmul_1_X(
+; fmul X, 1.0 ==> X
+define double @fmul_X_1(double %a) {
+; CHECK-LABEL: @fmul_X_1(
 ; CHECK-NEXT:    ret double [[A:%.*]]
 ;
   %b = fmul double 1.0, %a


        


More information about the llvm-commits mailing list