[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 11:20:51 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:

Changed to check for LibCall action.
Changes in one LoongArch test were reverted, probably for good.


https://github.com/llvm/llvm-project/pull/99752


More information about the llvm-commits mailing list