-
Notifications
You must be signed in to change notification settings - Fork 15.2k
DAG: Use modf vector libcalls through RuntimeLibcalls #166986
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
arsenm
merged 3 commits into
main
from
users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls
Nov 12, 2025
Merged
DAG: Use modf vector libcalls through RuntimeLibcalls #166986
arsenm
merged 3 commits into
main
from
users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls
Nov 12, 2025
+106
−43
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) ChangesCopy new process from sincos/sincospi Full diff: https://github.com/llvm/llvm-project/pull/166986.diff 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index a52ad41d0f1b3..944e1714e8f98 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -313,33 +313,17 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
Type *Ty = getContainedTypes(RetTy).front();
EVT VT = getTLI()->getValueType(DL, Ty);
- EVT ScalarVT = VT.getScalarType();
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
- /// Migration flag. IsVectorCall cases directly know about the vector
- /// libcall in RuntimeLibcallsInfo and shouldn't try to use
- /// LibInfo->getVectorMappingInfo.
- bool IsVectorCall = false;
-
switch (ICA.getID()) {
case Intrinsic::modf:
- LC = RTLIB::getMODF(ScalarVT);
+ LC = RTLIB::getMODF(VT);
break;
case Intrinsic::sincospi:
LC = RTLIB::getSINCOSPI(VT);
- if (LC == RTLIB::UNKNOWN_LIBCALL)
- LC = RTLIB::getSINCOSPI(ScalarVT);
- else if (VT.isVector())
- IsVectorCall = true;
-
break;
case Intrinsic::sincos:
LC = RTLIB::getSINCOS(VT);
- if (LC == RTLIB::UNKNOWN_LIBCALL)
- LC = RTLIB::getSINCOS(ScalarVT);
- else if (VT.isVector())
- IsVectorCall = true;
-
break;
default:
return std::nullopt;
@@ -350,33 +334,14 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
if (LibcallImpl == RTLIB::Unsupported)
return std::nullopt;
- StringRef LCName =
- RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpl);
-
- // Search for a corresponding vector variant.
- //
- // FIXME: Should use RuntimeLibcallsInfo, not TargetLibraryInfo to get the
- // vector mapping.
LLVMContext &Ctx = RetTy->getContext();
- ElementCount VF = getVectorizedTypeVF(RetTy);
- VecDesc const *VD = nullptr;
-
- if (!IsVectorCall) {
- for (bool Masked : {false, true}) {
- if ((VD = LibInfo->getVectorMappingInfo(LCName, VF, Masked)))
- break;
- }
- if (!VD)
- return std::nullopt;
- }
// Cost the call + mask.
auto Cost =
thisT()->getCallInstrCost(nullptr, RetTy, ICA.getArgTypes(), CostKind);
- if ((VD && VD->isMasked()) ||
- (IsVectorCall &&
- RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl))) {
+ if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
+ ElementCount VF = getVectorizedTypeVF(RetTy);
auto VecTy = VectorType::get(IntegerType::getInt1Ty(Ctx), VF);
Cost += thisT()->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy,
VecTy, {}, CostKind, 0, nullptr, {});
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
index 78d8ea0676dd7..a7ae794459331 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
@@ -1283,9 +1283,10 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
break;
}
case ISD::FMODF: {
- EVT VT = Node->getValueType(0).getVectorElementType();
+ EVT VT = Node->getValueType(0);
RTLIB::Libcall LC = RTLIB::getMODF(VT);
- if (DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
+ if (LC != RTLIB::UNKNOWN_LIBCALL &&
+ DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
/*CallRetResNo=*/0))
return;
break;
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index b4eb6c357e10e..a5fc609ee8f61 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -476,6 +476,24 @@ RTLIB::Libcall RTLIB::getSINCOS_STRET(EVT RetVT) {
}
RTLIB::Libcall RTLIB::getMODF(EVT RetVT) {
+ // TODO: Tablegen should generate this function
+ if (RetVT.isVector()) {
+ if (!RetVT.isSimple())
+ return RTLIB::UNKNOWN_LIBCALL;
+ switch (RetVT.getSimpleVT().SimpleTy) {
+ case MVT::v4f32:
+ return RTLIB::MODF_V4F32;
+ case MVT::v2f64:
+ return RTLIB::MODF_V2F64;
+ case MVT::nxv4f32:
+ return RTLIB::MODF_NXV4F32;
+ case MVT::nxv2f64:
+ return RTLIB::MODF_NXV2F64;
+ default:
+ return RTLIB::UNKNOWN_LIBCALL;
+ }
+ }
+
return getFPLibCall(RetVT, MODF_F32, MODF_F64, MODF_F80, MODF_F128,
MODF_PPCF128);
}
|
58e7e95 to
a6eb2c1
Compare
b66f444 to
f455421
Compare
This was referenced Nov 7, 2025
This was referenced Nov 8, 2025
MacDue
approved these changes
Nov 10, 2025
RKSimon
approved these changes
Nov 10, 2025
ilovepi
approved these changes
Nov 10, 2025
a6eb2c1 to
f2c1217
Compare
67b8475 to
7d5abd2
Compare
f2c1217 to
90ec028
Compare
90ec028 to
91dee19
Compare
7d5abd2 to
61a9e50
Compare
Base automatically changed from
users/arsenm/runtime-libcalls/add-vector-entries-modf-sleef-armpl
to
main
November 12, 2025 02:01
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.

Copy new process from sincos/sincospi