Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Nov 7, 2025

Only use RuntimeLibcallsInfo. Remove the helper functions used to
transition.

Copy link
Contributor Author

arsenm commented Nov 7, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Matt Arsenault (arsenm)

Changes

Only use RuntimeLibcallsInfo. Remove the helper functions used to
transition.


Full diff: https://github.com/llvm/llvm-project/pull/166987.diff

5 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+1-9)
  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (+2-2)
  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp (+1-2)
  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp (+2-2)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+10-50)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index c8db97cc42a30..0dd4f23c6d85f 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -1725,17 +1725,9 @@ class SelectionDAG {
   /// value.
   LLVM_ABI bool
   expandMultipleResultFPLibCall(RTLIB::Libcall LC, SDNode *Node,
-                                SmallVectorImpl<SDValue> &Results, EVT CallType,
+                                SmallVectorImpl<SDValue> &Results,
                                 std::optional<unsigned> CallRetResNo = {});
 
-  // FIXME: Ths should be removed, and form using RTLIB::Libcall should be
-  // preferred. Callers should resolve the exact type libcall to use.
-  LLVM_ABI bool
-  expandMultipleResultFPLibCall(StringRef LibcallName, CallingConv::ID CC,
-                                SDNode *Node, SmallVectorImpl<SDValue> &Results,
-                                std::optional<unsigned> CallRetResNo = {},
-                                bool IsVectorMasked = false);
-
   /// Expand the specified \c ISD::VAARG node as the Legalize pass would.
   LLVM_ABI SDValue expandVAArg(SDNode *Node);
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index a0baf821698a8..3ed84af6a8717 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -4842,7 +4842,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
     RTLIB::Libcall LC = Node->getOpcode() == ISD::FSINCOS
                             ? RTLIB::getSINCOS(VT)
                             : RTLIB::getSINCOSPI(VT);
-    bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT);
+    bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results);
     if (!Expanded) {
       DAG.getContext()->emitError(Twine("no libcall available for ") +
                                   Node->getOperationName(&DAG));
@@ -4940,7 +4940,7 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
     EVT VT = Node->getValueType(0);
     RTLIB::Libcall LC = Node->getOpcode() == ISD::FMODF ? RTLIB::getMODF(VT)
                                                         : RTLIB::getFREXP(VT);
-    bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
+    bool Expanded = DAG.expandMultipleResultFPLibCall(LC, Node, Results,
                                                       /*CallRetResNo=*/0);
     if (!Expanded)
       llvm_unreachable("Expected scalar FFREXP/FMODF to expand to libcall!");
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index 29c4dac12a81a..58983cb57d7f6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -1726,8 +1726,7 @@ void DAGTypeLegalizer::ExpandFloatRes_UnaryWithTwoFPResults(
     SDNode *N, RTLIB::Libcall LC, std::optional<unsigned> CallRetResNo) {
   assert(!N->isStrictFPOpcode() && "strictfp not implemented");
   SmallVector<SDValue> Results;
-  DAG.expandMultipleResultFPLibCall(LC, N, Results, N->getValueType(0),
-                                    CallRetResNo);
+  DAG.expandMultipleResultFPLibCall(LC, N, Results, CallRetResNo);
   for (auto [ResNo, Res] : enumerate(Results)) {
     SDValue Lo, Hi;
     GetPairElements(Res, Lo, Hi);
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
index a7ae794459331..c55e55df373e9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
@@ -1275,7 +1275,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
                             ? RTLIB::getSINCOS(VT)
                             : RTLIB::getSINCOSPI(VT);
     if (LC != RTLIB::UNKNOWN_LIBCALL &&
-        DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT))
+        DAG.expandMultipleResultFPLibCall(LC, Node, Results))
       return;
 
     // TODO: Try to see if there's a narrower call available to use before
@@ -1286,7 +1286,7 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
     EVT VT = Node->getValueType(0);
     RTLIB::Libcall LC = RTLIB::getMODF(VT);
     if (LC != RTLIB::UNKNOWN_LIBCALL &&
-        DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
+        DAG.expandMultipleResultFPLibCall(LC, Node, Results,
                                           /*CallRetResNo=*/0))
       return;
     break;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index a69216e1a0e7f..d4e80f85087bc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2515,56 +2515,14 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
 
 bool SelectionDAG::expandMultipleResultFPLibCall(
     RTLIB::Libcall LC, SDNode *Node, SmallVectorImpl<SDValue> &Results,
-    EVT CallVT, std::optional<unsigned> CallRetResNo) {
+    std::optional<unsigned> CallRetResNo) {
   if (LC == RTLIB::UNKNOWN_LIBCALL)
     return false;
 
-  EVT VT = Node->getValueType(0);
-
-  RTLIB::LibcallImpl Impl = TLI->getLibcallImpl(LC);
-  if (Impl == RTLIB::Unsupported)
-    return false;
-
-  StringRef LCName = TLI->getLibcallImplName(Impl);
-
-  // FIXME: This should not use TargetLibraryInfo. There should be
-  // RTLIB::Libcall entries for each used vector type, and directly matched.
-  auto getVecDesc = [&]() -> VecDesc const * {
-    for (bool Masked : {false, true}) {
-      if (VecDesc const *VD = getLibInfo().getVectorMappingInfo(
-              LCName, VT.getVectorElementCount(), Masked)) {
-        return VD;
-      }
-    }
-    return nullptr;
-  };
-
-  // For vector types, we must find a vector mapping for the libcall.
-  VecDesc const *VD = nullptr;
-  if (VT.isVector() && !CallVT.isVector() && !(VD = getVecDesc()))
+  RTLIB::LibcallImpl LibcallImpl = TLI->getLibcallImpl(LC);
+  if (LibcallImpl == RTLIB::Unsupported)
     return false;
 
-  bool IsMasked = (VD && VD->isMasked()) ||
-                  RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(Impl);
-
-  // This wrapper function exists because getVectorMappingInfo works in terms of
-  // function names instead of RTLIB enums.
-
-  // FIXME: If we used a vector mapping, this assumes the calling convention of
-  // the vector function is the same as the scalar.
-
-  StringRef Name = VD ? VD->getVectorFnName() : LCName;
-
-  return expandMultipleResultFPLibCall(Name,
-                                       TLI->getLibcallImplCallingConv(Impl),
-                                       Node, Results, CallRetResNo, IsMasked);
-}
-
-// FIXME: This belongs in TargetLowering
-bool SelectionDAG::expandMultipleResultFPLibCall(
-    StringRef Name, CallingConv::ID CC, SDNode *Node,
-    SmallVectorImpl<SDValue> &Results, std::optional<unsigned> CallRetResNo,
-    bool IsMasked) {
   LLVMContext &Ctx = *getContext();
   EVT VT = Node->getValueType(0);
   unsigned NumResults = Node->getNumValues();
@@ -2625,8 +2583,8 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
 
   SDLoc DL(Node);
 
-  // Pass the vector mask (if required).
-  if (IsMasked) {
+  if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
+    // Pass the vector mask (if required).
     EVT MaskVT = TLI->getSetCCResultType(getDataLayout(), Ctx, VT);
     SDValue Mask = getBoolConstant(true, DL, MaskVT, VT);
     Args.emplace_back(Mask, MaskVT.getTypeForEVT(Ctx));
@@ -2637,10 +2595,12 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
                       : Type::getVoidTy(Ctx);
   SDValue InChain = StoresInChain ? StoresInChain : getEntryNode();
   SDValue Callee =
-      getExternalSymbol(Name.data(), TLI->getPointerTy(getDataLayout()));
+      getExternalSymbol(TLI->getLibcallImplName(LibcallImpl).data(),
+                        TLI->getPointerTy(getDataLayout()));
   TargetLowering::CallLoweringInfo CLI(*this);
-  CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(CC, RetType, Callee,
-                                                     std::move(Args));
+  CLI.setDebugLoc(DL).setChain(InChain).setLibCallee(
+      TLI->getLibcallImplCallingConv(LibcallImpl), RetType, Callee,
+      std::move(Args));
 
   auto [Call, CallChain] = TLI->LowerCallTo(CLI);
 

@arsenm arsenm force-pushed the users/arsenm/dag/remove-tli-vector-codegen branch from 5d2009c to faeead5 Compare November 7, 2025 22:39
@arsenm arsenm force-pushed the users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls branch from 58e7e95 to a6eb2c1 Compare November 7, 2025 22:39
@arsenm arsenm force-pushed the users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls branch from a6eb2c1 to f2c1217 Compare November 10, 2025 18:18
@arsenm arsenm force-pushed the users/arsenm/dag/remove-tli-vector-codegen branch 2 times, most recently from 990eb1e to dc62ebd Compare November 10, 2025 19:22
@arsenm arsenm force-pushed the users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls branch from f2c1217 to 90ec028 Compare November 10, 2025 19:22
@arsenm arsenm force-pushed the users/arsenm/dag/remove-tli-vector-codegen branch from dc62ebd to d585f3e Compare November 12, 2025 00:57
@arsenm arsenm force-pushed the users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls branch from 90ec028 to 91dee19 Compare November 12, 2025 00:57
Base automatically changed from users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls to main November 12, 2025 02:05
Only use RuntimeLibcallsInfo. Remove the helper functions used to
transition.
@arsenm arsenm force-pushed the users/arsenm/dag/remove-tli-vector-codegen branch from d585f3e to 6584d5b Compare November 12, 2025 02:11
@arsenm arsenm enabled auto-merge (squash) November 12, 2025 02:16
@arsenm arsenm merged commit 95f2728 into main Nov 12, 2025
7 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/dag/remove-tli-vector-codegen branch November 12, 2025 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants