[llvm-branch-commits] [llvm] DAG: Avoid asserting on libcall action if function is unavailable (PR #170585)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Dec 3 16:32:47 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/170585.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (+12-7)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 94a3386e75394..ac8532d34d0d6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -4102,14 +4102,19 @@ 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)
``````````
</details>
https://github.com/llvm/llvm-project/pull/170585
More information about the llvm-branch-commits
mailing list