[llvm] r373459 - [InstCombine] Simplify fma multiplication to nan for undef or nan operands.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 05:32:52 PDT 2019


Author: fhahn
Date: Wed Oct  2 05:32:52 2019
New Revision: 373459

URL: http://llvm.org/viewvc/llvm-project?rev=373459&view=rev
Log:
[InstCombine] Simplify fma multiplication to nan for undef or nan operands.

In similar fashion to D67721, we can simplify FMA multiplications if any
of the operands is NaN or undef. In instcombine, we will simplify the
FMA to an fadd with a NaN operand, which in turn gets folded to NaN.

Note that this just changes SimplifyFMAFMul, so we still not catch the
case where only the Add part of the FMA is Nan/Undef.

Reviewers: cameron.mcinally, mcberg2017, spatel, arsenm

Reviewed By: cameron.mcinally

Differential Revision: https://reviews.llvm.org/D68265

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=373459&r1=373458&r2=373459&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Wed Oct  2 05:32:52 2019
@@ -4592,6 +4592,9 @@ static Value *SimplifyFSubInst(Value *Op
 
 static Value *SimplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
                               const SimplifyQuery &Q, unsigned MaxRecurse) {
+  if (Constant *C = simplifyFPOp({Op0, Op1}))
+    return C;
+
   // fmul X, 1.0 ==> X
   if (match(Op1, m_FPOne()))
     return Op0;
@@ -4626,9 +4629,6 @@ static Value *SimplifyFMulInst(Value *Op
   if (Constant *C = foldOrCommuteConstant(Instruction::FMul, Op0, Op1, Q))
     return C;
 
-  if (Constant *C = simplifyFPOp({Op0, Op1}))
-    return C;
-
   // Now apply simplifications that do not require rounding.
   return SimplifyFMAFMul(Op0, Op1, FMF, Q, MaxRecurse);
 }




More information about the llvm-commits mailing list