[llvm] SelectionDAG: Improve expandFP_TO_INT_SAT (PR #139217)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri May 9 04:47:55 PDT 2025


================
@@ -11542,22 +11542,47 @@ SDValue TargetLowering::expandFP_TO_INT_SAT(SDNode *Node,
   // If the integer bounds are exactly representable as floats and min/max are
   // legal, emit a min+max+fptoi sequence. Otherwise we have to use a sequence
   // of comparisons and selects.
-  bool MinMaxLegal = isOperationLegal(ISD::FMINNUM, SrcVT) &&
+  bool MinMax2019NumLegal = isOperationLegal(ISD::FMINIMUMNUM, SrcVT) &&
+                     isOperationLegal(ISD::FMAXIMUMNUM, SrcVT);
+  bool MinMax2019Legal = isOperationLegal(ISD::FMINIMUM, SrcVT) &&
+                     isOperationLegal(ISD::FMAXIMUM, SrcVT);
+  bool MinMax2008Legal = isOperationLegal(ISD::FMINNUM, SrcVT) &&
                      isOperationLegal(ISD::FMAXNUM, SrcVT);
-  if (AreExactFloatBounds && MinMaxLegal) {
-    SDValue Clamped = Src;
 
-    // Clamp Src by MinFloat from below. If Src is NaN the result is MinFloat.
-    Clamped = DAG.getNode(ISD::FMAXNUM, dl, SrcVT, Clamped, MinFloatNode);
-    // Clamp by MaxFloat from above. NaN cannot occur.
-    Clamped = DAG.getNode(ISD::FMINNUM, dl, SrcVT, Clamped, MaxFloatNode);
+  if (AreExactFloatBounds && (MinMax2019NumLegal || MinMax2019Legal || MinMax2008Legal)) {
----------------
arsenm wrote:

Can we just stick to one, and let separate combines take care of the expansion to one of the other pairs 

https://github.com/llvm/llvm-project/pull/139217


More information about the llvm-commits mailing list