[llvm] [AMDGPU] Narrow an int to fp source that fits in half its width (PR #223107)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 13:34:16 PDT 2026


================
@@ -20542,6 +20542,33 @@ static SDValue foldFPToIntToFP(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
   return Result;
 }
 
+// Narrow an integer source that fits in half its width when the target finds
+// the wide type undesirable for the conversion.
+static SDValue narrowIntToFPSource(SDNode *N, const SDLoc &DL,
+                                   SelectionDAG &DAG,
+                                   const TargetLowering &TLI) {
+  unsigned Opc = N->getOpcode();
+  SDValue N0 = N->getOperand(0);
+  EVT OpVT = N0.getValueType();
+  if (!OpVT.isScalarInteger() || !TLI.isTypeLegal(OpVT) ||
+      TLI.isTypeDesirableForOp(Opc, OpVT))
+    return SDValue();
+
+  EVT HalfVT = OpVT.getHalfSizedIntegerVT(*DAG.getContext());
+  if (!TLI.isTypeDesirableForOp(Opc, HalfVT) ||
+      !TLI.isOperationLegalOrCustom(Opc, HalfVT))
+    return SDValue();
+
+  unsigned SrcBits = Opc == ISD::SINT_TO_FP
+                         ? DAG.ComputeMaxSignificantBits(N0)
+                         : DAG.computeKnownBits(N0).countMaxActiveBits();
+  if (SrcBits > HalfVT.getSizeInBits())
----------------
arsenm wrote:

Alternatively, you can pick the next largest legal integer type based on SrcBits 

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


More information about the llvm-commits mailing list