[llvm-branch-commits] [llvm] DAG: Stop using TargetLibraryInfo for multi-result FP intrinsic codegen (PR #166987)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 10 10:18:20 PST 2025
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/166987
>From 990eb1e0210b76c5abd76fca30c923de3d30b4ec Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 6 Nov 2025 21:55:35 -0800
Subject: [PATCH] DAG: Stop using TargetLibraryInfo for multi-result FP
intrinsic codegen
Only use RuntimeLibcallsInfo. Remove the helper functions used to
transition.
---
llvm/include/llvm/CodeGen/SelectionDAG.h | 10 +---
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 4 +-
.../SelectionDAG/LegalizeFloatTypes.cpp | 3 +-
.../SelectionDAG/LegalizeVectorOps.cpp | 4 +-
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 60 ++++---------------
5 files changed, 16 insertions(+), 65 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index 62d2f222110e4..5b331e4444915 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 b5d502b90c90c..f05266967fb68 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2514,56 +2514,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();
@@ -2624,8 +2582,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));
@@ -2636,10 +2594,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);
More information about the llvm-branch-commits
mailing list