[llvm] [AMDGPU] Limit promoting allocas that have users with dynamic index above a threshold on number of elements (PR #170327)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 09:06:47 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index aba660ffb..23250025c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -85,9 +85,10 @@ static cl::opt<unsigned>
                             "when sorting profitable allocas"),
                    cl::init(4));
 
-static cl::opt<unsigned> DynIdxNumElmLimit("dynamic-index-num-element-limit",
+static cl::opt<unsigned> DynIdxNumElmLimit(
+    "dynamic-index-num-element-limit",
     cl::desc("Maximum number of elements for promoting alloca with dynamic"
-      " index"),
+             " index"),
     cl::init(8));
 
 // Shared implementation which can do both promotion to vector and to LDS.
@@ -924,20 +925,20 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToVector(AllocaInst &Alloca) {
       Value *Index = GEPToVectorIndex(GEP, &Alloca, VecEltTy, *DL, NewGEPInsts);
       if (!Index)
         return RejectUser(Inst, "cannot compute vector index for GEP");
-      
+
       if (!isa<ConstantInt>(Index)) {
         bool UsedInLoad = false;
         for (auto *U : GEP->users()) {
-          if(isa<LoadInst>(U)) {
+          if (isa<LoadInst>(U)) {
             UsedInLoad = true;
             break;
           }
         }
-        if (auto *UserVecTy = dyn_cast<FixedVectorType>(
-                GEP->getSourceElementType())) {
+        if (auto *UserVecTy =
+                dyn_cast<FixedVectorType>(GEP->getSourceElementType())) {
           if (UsedInLoad && UserVecTy->getNumElements() > DynIdxNumElmLimit) {
-            return RejectUser(Inst, 
-              "user has too many number of elements for dynamic index");
+            return RejectUser(
+                Inst, "user has too many number of elements for dynamic index");
           }
         }
       }

``````````

</details>


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


More information about the llvm-commits mailing list