[llvm] [TargetLowering][SelectionDAG] Exploit nneg Flag in UINT_TO_FP (PR #108931)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 08:24:38 PDT 2024


================
@@ -8361,18 +8361,26 @@ bool TargetLowering::expandFP_TO_UINT(SDNode *Node, SDValue &Result,
 }
 
 bool TargetLowering::expandUINT_TO_FP(SDNode *Node, SDValue &Result,
-                                      SDValue &Chain,
-                                      SelectionDAG &DAG) const {
+                                      SDValue &Chain, SelectionDAG &DAG) const {
+  SDValue Src = Node->getOperand(0);
+  EVT SrcVT = Src.getValueType();
+  EVT DstVT = Node->getValueType(0);
+
+  // If the input is known to be non-negative and SINT_TO_FP is legal then use
+  // it.
+  if (Node->getFlags().hasNonNeg() &&
+      isOperationLegalOrCustom(ISD::SINT_TO_FP, DstVT)) {
----------------
arsenm wrote:

Yes, that is what the legalizer actually checks: https://github.com/llvm/llvm-project/blob/556ec4a7261447d13703816cd3730a891441e52c/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp#L1012

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


More information about the llvm-commits mailing list