Skip to content

Commit 5a47ed2

Browse files
committed
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.
1 parent 65dee89 commit 5a47ed2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,14 +4102,20 @@ void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, SDValue &Lo, SDValue &Hi) {
41024102

41034103
if (TLI.getOperationAction(ISD::CTPOP, VT) == TargetLoweringBase::LibCall) {
41044104
RTLIB::Libcall LC = RTLIB::getCTPOP(VT);
4105-
assert(LC != RTLIB::UNKNOWN_LIBCALL && TLI.getLibcallName(LC) &&
4105+
assert(LC != RTLIB::UNKNOWN_LIBCALL &&
41064106
"LibCall explicitly requested, but not available");
4107-
TargetLowering::MakeLibCallOptions CallOptions;
4108-
EVT IntVT =
4109-
EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
4110-
SDValue Res = TLI.makeLibCall(DAG, LC, IntVT, Op, CallOptions, DL).first;
4111-
SplitInteger(DAG.getSExtOrTrunc(Res, DL, VT), Lo, Hi);
4112-
return;
4107+
4108+
if (RTLIB::LibcallImpl LCImpl = TLI.getLibcallImpl(LC)) {
4109+
TargetLowering::MakeLibCallOptions CallOptions;
4110+
EVT IntVT =
4111+
EVT::getIntegerVT(*DAG.getContext(), DAG.getLibInfo().getIntSize());
4112+
SDValue Res =
4113+
TLI.makeLibCall(DAG, LCImpl, IntVT, Op, CallOptions, DL).first;
4114+
SplitInteger(DAG.getSExtOrTrunc(Res, DL, VT), Lo, Hi);
4115+
return;
4116+
}
4117+
4118+
// If the function is not available, fall back on the expansion.
41134119
}
41144120

41154121
// ctpop(HiLo) -> ctpop(Hi)+ctpop(Lo)

0 commit comments

Comments
 (0)