[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 09:55:17 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
----------------
s-barannikov wrote:

If we expand it later, we will end up with two libcalls for an illegal type instead of one (best case), or those two libcalls will be expanded into scalar code. You can see the difference in [this commit](https://github.com/llvm/llvm-project/pull/99752/commits/f90a6b46a8a9639bad8f2aa826150a47727d6b82).
This is primarily for 32-bit targets calling i64 CTPOP.


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


More information about the llvm-commits mailing list