[llvm] [SDag][ARM][RISCV] Allow lowering CTPOP into a libcall (PR #99752)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 10:17:23 PDT 2024
================
@@ -3847,15 +3847,36 @@ void DAGTypeLegalizer::ExpandIntRes_CTLZ(SDNode *N,
Hi = DAG.getConstant(0, dl, NVT);
}
-void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N,
- SDValue &Lo, SDValue &Hi) {
- SDLoc dl(N);
+void DAGTypeLegalizer::ExpandIntRes_CTPOP(SDNode *N, SDValue &Lo, SDValue &Hi) {
+ SDValue Op = N->getOperand(0);
+ EVT VT = N->getValueType(0);
+ SDLoc DL(N);
+
+ // If the narrow CTPOP is not supported by the target, try to convert it
+ // to a libcall.
+ EVT ExpandedVT = TLI.getTypeToExpandTo(*DAG.getContext(), VT);
+ if (!TLI.isOperationLegalOrCustom(ISD::CTPOP, ExpandedVT)) {
----------------
s-barannikov wrote:
I was thinking about this too, but I found [only one](https://github.com/llvm/llvm-project/blob/bb8a735facb710a07601d3bc9c45316f0de9d68d/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp#L1344) place where LibCall action is checked. That made me wonder if this is the right thing to do. Hopefully someone can tell for sure.
https://github.com/llvm/llvm-project/pull/99752
More information about the llvm-commits
mailing list