[PATCH] D70208: [SimplifyCFG] propagate fast-math-flags (FMF) from phi to select

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 15 13:22:02 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rGee0882bdf866: [SimplifyCFG] propagate fast-math-flags (FMF) from phi to select (authored by spatel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70208/new/

https://reviews.llvm.org/D70208

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/HoistCode.ll


Index: llvm/test/Transforms/SimplifyCFG/HoistCode.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/HoistCode.ll
+++ llvm/test/Transforms/SimplifyCFG/HoistCode.ll
@@ -19,7 +19,7 @@
 ; CHECK-LABEL: @PR39535min(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TOBOOL:%.*]] = fcmp une float [[X:%.*]], 0.000000e+00
-; CHECK-NEXT:    [[DOTX:%.*]] = select i1 [[TOBOOL]], float 0.000000e+00, float [[X]]
+; CHECK-NEXT:    [[DOTX:%.*]] = select fast i1 [[TOBOOL]], float 0.000000e+00, float [[X]]
 ; CHECK-NEXT:    ret float [[DOTX]]
 ;
 entry:
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1404,10 +1404,16 @@
       // These values do not agree.  Insert a select instruction before NT
       // that determines the right value.
       SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)];
-      if (!SI)
+      if (!SI) {
+        // Propagate fast-math-flags from phi node to its replacement select.
+        IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
+        if (isa<FPMathOperator>(PN))
+          Builder.setFastMathFlags(PN.getFastMathFlags());
+
         SI = cast<SelectInst>(
             Builder.CreateSelect(BI->getCondition(), BB1V, BB2V,
                                  BB1V->getName() + "." + BB2V->getName(), BI));
+      }
 
       // Make the PHI node use the select for all incoming values for BB1/BB2
       for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70208.229631.patch
Type: text/x-patch
Size: 1627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191115/013bca36/attachment-0001.bin>


More information about the llvm-commits mailing list