https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/170585

>From 5a47ed272b0243ac5d91aeeec032df4cb842477a Mon Sep 17 00:00:00 2001
From: Matt Arsenault <[email protected]>
Date: Wed, 3 Dec 2025 23:50:44 +0100
Subject: [PATCH] DAG: Avoid asserting on libcall action if function is
 unavailable

Eventually the set of available functions will be a program
dependent property, which could diverge from the static table of
functions for the subtarget. In that case, fall back to the usual
expansion.
---
 .../SelectionDAG/LegalizeIntegerTypes.cpp     | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp 
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 94a3386e75394..8410f47fd5417 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -4102,14 +4102,20 @@ void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, 
SDValue &Lo, SDValue &Hi) {
 
   if (TLI.getOperationAction(ISD::CTPOP, VT) == TargetLoweringBase::LibCall) {
     RTLIB::Libcall LC = RTLIB::getCTPOP(VT);
-    assert(LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC) &&
+    assert(LC != RTLIB::UNKNOWN_LIBCALL &&
            "LibCall explicitly requested, but not available");
-    TargetLowering::MakeLibCallOptions CallOptions;
-    EVT IntVT =
-        EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
-    SDValue Res = TLI.makeLibCall(DAG, LC, IntVT, Op, CallOptions, DL).first;
-    SplitInteger(DAG.getSExtOrTrunc(Res, DL, VT), Lo, Hi);
-    return;
+
+    if (RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC)) {
+      TargetLowering::MakeLibCallOptions CallOptions;
+      EVT IntVT =
+          EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
+      SDValue Res =
+          TLI.makeLibCall(DAG, LCImpl, IntVT, Op, CallOptions, DL).first;
+      SplitInteger(DAG.getSExtOrTrunc(Res, DL, VT), Lo, Hi);
+      return;
+    }
+
+    // If the function is not available, fall back on the expansion.
   }
 
   // ctpop(HiLo) -> ctpop(Hi)+ctpop(Lo)

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

Reply via email to