[llvm] r287695 - Fixed the lost FastMathFlags in Reassociate optimization.

Vyacheslav Klochkov via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 12:23:04 PST 2016


Author: v_klochkov
Date: Tue Nov 22 14:23:04 2016
New Revision: 287695

URL: http://llvm.org/viewvc/llvm-project?rev=287695&view=rev
Log:
Fixed the lost FastMathFlags in Reassociate optimization.
Reviewer: Hal Finkel.
Differential Revision: https://reviews.llvm.org/D26957


Added:
    llvm/trunk/test/Transforms/Reassociate/propagate-flags.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=287695&r1=287694&r2=287695&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Tue Nov 22 14:23:04 2016
@@ -1778,6 +1778,12 @@ Value *ReassociatePass::OptimizeMul(Bina
     return nullptr; // All distinct factors, so nothing left for us to do.
 
   IRBuilder<> Builder(I);
+  // The reassociate transformation for FP operations is performed only
+  // if unsafe algebra is permitted by FastMathFlags. Propagate those flags
+  // to the newly generated operations.
+  if (auto FPI = dyn_cast<FPMathOperator>(I))
+    Builder.setFastMathFlags(FPI->getFastMathFlags());
+
   Value *V = buildMinimalMultiplyDAG(Builder, Factors);
   if (Ops.empty())
     return V;

Added: llvm/trunk/test/Transforms/Reassociate/propagate-flags.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/propagate-flags.ll?rev=287695&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/propagate-flags.ll (added)
+++ llvm/trunk/test/Transforms/Reassociate/propagate-flags.ll Tue Nov 22 14:23:04 2016
@@ -0,0 +1,14 @@
+; RUN: opt < %s -reassociate -S | FileCheck %s
+ 
+; CHECK-LABEL: func
+; CHECK:       fmul fast double
+; CHECK-NEXT:  fmul fast double
+; CHECK-NEXT:  ret
+
+define double @func(double %a, double %b) {
+entry:
+  %mul1 = fmul fast double %a, %a
+  %mul2 = fmul fast double %b, %b
+  %mul3 = fmul fast double %mul1, %mul2
+  ret double %mul3
+}




More information about the llvm-commits mailing list