[llvm] 7f7a0f2 - [InstSimplify] reduce code duplication for fmul folds; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 4 07:39:16 PDT 2022


Author: Sanjay Patel
Date: 2022-10-04T10:29:53-04:00
New Revision: 7f7a0f2f83c741908407a16c1c4f6a671b6b6081

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

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

This is a modification of the earlier attempt from:
7b7940f9da80

For fma callers, we only want to swap a 0.0 or 1.0 constant.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index c7a16562b901..786ed03d476a 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5325,22 +5325,18 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
   if (!isDefaultFPEnvironment(ExBehavior, Rounding))
     return nullptr;
 
-  // fmul X, 1.0 ==> X
+  // Canonicalize special constants as operand 1.
+  if (match(Op0, m_FPOne()) || match(Op0, m_AnyZeroFP()))
+    std::swap(Op0, Op1);
+
+  // X * 1.0 --> X
   if (match(Op1, m_FPOne()))
     return Op0;
 
-  // fmul 1.0, X ==> X
-  if (match(Op0, m_FPOne()))
-    return Op1;
-
-  // fmul nnan nsz X, 0 ==> 0
+  // X * 0.0 --> 0.0 (with nnan and nsz)
   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.


        


More information about the llvm-commits mailing list