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

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 09:58:39 PDT 2026


================
@@ -66,47 +66,58 @@ static bool runNVVMIntrRange(Function &F) {
   if (!isKernelFunction(F))
     return false;
 
-  const auto OverallReqNTID = getOverallReqNTID(F);
+  const auto ReqNTID = getReqNTID(F);
   const auto OverallMaxNTID = getOverallMaxNTID(F);
   const auto OverallClusterRank = getOverallClusterRank(F);
 
   // If this function lacks any range information, do nothing.
-  if (!(OverallReqNTID || OverallMaxNTID || OverallClusterRank))
+  if (!(!ReqNTID.empty() || OverallMaxNTID || OverallClusterRank))
     return false;
 
-  const unsigned FunctionNTID = OverallReqNTID.value_or(
-      OverallMaxNTID.value_or(std::numeric_limits<unsigned>::max()));
+  const unsigned MaxNTID =
+      OverallMaxNTID.value_or(std::numeric_limits<unsigned>::max());
 
   const unsigned FunctionClusterRank =
       OverallClusterRank.value_or(std::numeric_limits<unsigned>::max());
 
-  const Vector3 MaxBlockSize{std::min(1024u, FunctionNTID),
-                             std::min(1024u, FunctionNTID),
-                             std::min(64u, FunctionNTID)};
+  // When reqntid is specified, block dimensions are exact compile-time
+  // constants. Otherwise, use maxntid (capped at hardware limits) as upper
+  // bounds.
+  Vector3 MinBlockDim, MaxBlockDim;
+  if (!ReqNTID.empty()) {
+    MinBlockDim =
+        MaxBlockDim = {ReqNTID[0], ReqNTID.size() > 1 ? ReqNTID[1] : 1,
+                       ReqNTID.size() > 2 ? ReqNTID[2] : 1};
----------------
AlexMaclean wrote:

nit: I think something like this should work
```
ReqNTID.resize(3, 1);
MinBlockDim = MaxBlockDim = ReqNTID;
```

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


More information about the llvm-commits mailing list