-
Notifications
You must be signed in to change notification settings - Fork 15.2k
DAG: Stop using TargetLibraryInfo for multi-result FP intrinsic codegen #166987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+16
−65
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Nov 7, 2025
Contributor
Author
Member
|
@llvm/pr-subscribers-llvm-selectiondag Author: Matt Arsenault (arsenm) ChangesOnly use RuntimeLibcallsInfo. Remove the helper functions used to Full diff: https://github.com/llvm/llvm-project/pull/166987.diff 5 Files Affected:
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);
|
5d2009c to
faeead5
Compare
58e7e95 to
a6eb2c1
Compare
ilovepi
approved these changes
Nov 7, 2025
This was referenced Nov 8, 2025
a6eb2c1 to
f2c1217
Compare
990eb1e to
dc62ebd
Compare
f2c1217 to
90ec028
Compare
dc62ebd to
d585f3e
Compare
90ec028 to
91dee19
Compare
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.
d585f3e to
6584d5b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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