[PATCH] D51646: DAG: Preserve FMF when creating fminnum/fmaxnum

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 5 11:58:53 PDT 2018


arsenm updated this revision to Diff 164095.
arsenm added a comment.

Split out DAG part


https://reviews.llvm.org/D51646

Files:
  include/llvm/CodeGen/SelectionDAGNodes.h
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp


Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1088,8 +1088,10 @@
       IncomingFlags.copyFMF(*FPMO);
       if (!Node->getFlags().isDefined())
         Node->setFlags(IncomingFlags);
+#if 0
       else
         Node->intersectFlagsWith(IncomingFlags);
+#endif
     }
   }
 
@@ -2946,6 +2948,7 @@
   auto BaseOps = {Cond};
   ISD::NodeType OpCode = Cond.getValueType().isVector() ?
     ISD::VSELECT : ISD::SELECT;
+  SDNodeFlags Flags;
 
   // Min/max matching is only viable if all output VTs are the same.
   if (is_splat(ValueVTs)) {
@@ -2967,6 +2970,8 @@
 
     Value *LHS, *RHS;
     auto SPR = matchSelectPattern(const_cast<User*>(&I), LHS, RHS);
+    Flags.copyFMF(SPR.FMF);
+
     ISD::NodeType Opc = ISD::DELETED_NODE;
     switch (SPR.Flavor) {
     case SPF_UMAX:    Opc = ISD::UMAX; break;
@@ -3031,7 +3036,7 @@
     Ops.push_back(SDValue(RHSVal.getNode(), RHSVal.getResNo() + i));
     Values[i] = DAG.getNode(OpCode, getCurSDLoc(),
                             LHSVal.getNode()->getValueType(LHSVal.getResNo()+i),
-                            Ops);
+                            Ops, Flags);
   }
 
   setValue(&I, DAG.getNode(ISD::MERGE_VALUES, getCurSDLoc(),
Index: include/llvm/CodeGen/SelectionDAGNodes.h
===================================================================
--- include/llvm/CodeGen/SelectionDAGNodes.h
+++ include/llvm/CodeGen/SelectionDAGNodes.h
@@ -378,15 +378,20 @@
         AllowContract(false), ApproximateFuncs(false),
         AllowReassociation(false) {}
 
+  /// Propagate the fast-math-flags from IR FastMathFlags
+  void copyFMF(FastMathFlags FMF) {
+    setNoNaNs(FMF.noNaNs());
+    setNoInfs(FMF.noInfs());
+    setNoSignedZeros(FMF.noSignedZeros());
+    setAllowReciprocal(FMF.allowReciprocal());
+    setAllowContract(FMF.allowContract());
+    setApproximateFuncs(FMF.approxFunc());
+    setAllowReassociation(FMF.allowReassoc());
+  }
+
   /// Propagate the fast-math-flags from an IR FPMathOperator.
   void copyFMF(const FPMathOperator &FPMO) {
-    setNoNaNs(FPMO.hasNoNaNs());
-    setNoInfs(FPMO.hasNoInfs());
-    setNoSignedZeros(FPMO.hasNoSignedZeros());
-    setAllowReciprocal(FPMO.hasAllowReciprocal());
-    setAllowContract(FPMO.hasAllowContract());
-    setApproximateFuncs(FPMO.hasApproxFunc());
-    setAllowReassociation(FPMO.hasAllowReassoc());
+    copyFMF(FPMO.getFastMathFlags());
   }
 
   /// Sets the state of the flags to the defined state.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51646.164095.patch
Type: text/x-patch
Size: 2607 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180905/3a8a3a32/attachment.bin>


More information about the llvm-commits mailing list