Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Nov 7, 2025

Copy new process from sincos/sincospi

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

Copy new process from sincos/sincospi


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

3 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+3-38)
  • (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp (+3-2)
  • (modified) llvm/lib/CodeGen/TargetLoweringBase.cpp (+18)
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);
 }

@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/runtime-libcalls/add-vector-entries-modf-sleef-armpl branch from b66f444 to f455421 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/runtime-libcalls/add-vector-entries-modf-sleef-armpl branch from 67b8475 to 7d5abd2 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/use-modf-vector-libcalls-through-runtime-libcalls branch from 90ec028 to 91dee19 Compare November 12, 2025 00:57
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/add-vector-entries-modf-sleef-armpl branch from 7d5abd2 to 61a9e50 Compare November 12, 2025 00:57
Base automatically changed from users/arsenm/runtime-libcalls/add-vector-entries-modf-sleef-armpl to main November 12, 2025 02:01
@arsenm arsenm merged commit 4b9771e into main Nov 12, 2025
10 of 16 checks passed
@arsenm arsenm deleted the users/arsenm/dag/use-modf-vector-libcalls-through-runtime-libcalls branch November 12, 2025 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:codegen llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants