[llvm] [NVPTX] Restrict BFE selection to native targets (PR #228685)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 00:06:18 PDT 2026


wenhu1024 wrote:

> Does this change improve performance or final generated SASS on any supported architecture? It seems like this instruction is not natively supported on any architecture. If anything, I'd lean towards disabling BFE/BFI folding on all modern SMs.这种改动是否真的能提升性能,或者让最终生成的 SASS 代码在支持的各种架构上表现更好呢?看起来这种指令在任何架构上都不是原生支持的。相反,我更倾向于在所有现代 SM 上禁用 BFE/BFI 折叠功能。

Thanks, you think deeper than me!


sm_70 (Volta) is the boundary here: Maxwell/Pascal (sm_5x/sm_6x) have native BFE/BFI SASS instructions, while Volta and later architectures no longer do. This is also reflected in NVIDIA's Binary Utilities documentation:
https://docs.nvidia.com/cuda/archive/12.9.0/cuda-binary-utilities/index.html


and I checked the final SASS:
Target | PTX | Result
-- | -- | --
sm_60 | bfe.u32 | Native BFE.U32
sm_60 | bfe.u64 | Expanded to multiple SASS instructions
sm_70 | bfe.u32 | No native BFE

proof:
[https://godbolt.org/z/Y7Ea9o3Tq](https://godbolt.org/z/Y7Ea9o3Tq)


tryBFE is still useful on older SMs: on sm_60, ptxas folds (x >> 8) & 0xff to BFE, but does not fold the equivalent (x & 0xff00) >> 8 form. and this is one case.
proof:
[https://godbolt.org/z/Ycs5oWcKE](https://godbolt.org/z/Ycs5oWcKE)

I've updated the patch to skip tryBFE on sm_70+, and to only form 32-bit BFE on older targets.

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


More information about the llvm-commits mailing list