https://github.com/arsenm created 
https://github.com/llvm/llvm-project/pull/166986

Copy new process from sincos/sincospi

>From 58e7e95199c07f8664b9cf2f12264626f858beb2 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Thu, 6 Nov 2025 21:26:29 -0800
Subject: [PATCH] DAG: Use modf vector libcalls through RuntimeLibcalls

Copy new process from sincos/sincospi
---
 llvm/include/llvm/CodeGen/BasicTTIImpl.h      | 41 ++-----------------
 .../SelectionDAG/LegalizeVectorOps.cpp        |  5 ++-
 llvm/lib/CodeGen/TargetLoweringBase.cpp       | 18 ++++++++
 3 files changed, 24 insertions(+), 40 deletions(-)

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);
 }

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to