[llvm] [NVPTX] Constant fold blockDim when reqntid is specified (PR #191575)

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 11 12:49:23 PDT 2026


================
@@ -90,23 +100,44 @@ static bool runNVVMIntrRange(Function &F) {
                                std::min(0xffffu, FunctionClusterRank),
                                std::min(0xffffu, FunctionClusterRank)};
 
-  const auto ProccessIntrinsic = [&](IntrinsicInst *II) -> bool {
+  // When reqntid is specified, ntid (blockDim) values are exact compile-time
+  // constants. Get per-dimension values for constant folding.
+  const Vector3 ReqBlockDim =
+      !ReqNTID.empty()
+          ? Vector3{ReqNTID[0], ReqNTID.size() > 1 ? ReqNTID[1] : 1,
+                    ReqNTID.size() > 2 ? ReqNTID[2] : 1}
+          : Vector3{};
+  // Only fold when reqntid values are within hardware limits.
----------------
AlexMaclean wrote:

I don't think it makes sense to silently skip folding when the values are not within HW limits. Is this designed to handle a specific real world case? If not, I'd lean towards emitting a diagnostic warning and folding with whatever value the attribute specifies. 

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


More information about the llvm-commits mailing list