[llvm] [llvm][SPIRV] Expose fast `popcnt` support for SPIR-V targets (PR #109845)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 11:42:48 PDT 2024


================
@@ -37,6 +38,15 @@ class SPIRVTTIImpl : public BasicTTIImplBase<SPIRVTTIImpl> {
   explicit SPIRVTTIImpl(const SPIRVTargetMachine *TM, const Function &F)
       : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
         TLI(ST->getTargetLowering()) {}
+
+  TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) {
+    // SPIR-V natively supports OpBitcount, per 3.53.14 in the spec, as such it
+    // is reasonable to assume the Op is fast / preferable to the expanded loop.
+    // Furthermore, this prevents information being lost if transforms are
+    // applied to SPIR-V before lowering to a concrete target.
+    assert(isPowerOf2_32(TyWidth) && "Ty width must be power of 2");
----------------
arsenm wrote:

The IR allows any bitwidth, this should not assert 

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


More information about the llvm-commits mailing list