[llvm] [RISCV][GISel] Legalize G_CTPOP. (PR #72005)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 16:26:44 PST 2023


================
@@ -80,6 +80,11 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST) {
       .maxScalar(0, sXLen)
       .lower();
 
+  getActionDefinitionsBuilder(G_CTPOP)
+      .maxScalar(0, sXLen)
----------------
topperc wrote:

There's an assumption here that the maximum bitcount for any possible value including illegal will fit in XLen bits. This should be true since LLVM's maximum integer type is i16777215.

Clamping the result type first gives better code when splitting s64 intoto two s32 ops on RV32. That will generate an s32 G_ADD to add the two ctpops together. Otherwise we would get an s64 G_ADD that also needs to split.

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


More information about the llvm-commits mailing list