[llvm] [AMDGPU] Promote allocas used by phi/select (PR #221870)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 07:37:57 PDT 2026
================
@@ -375,29 +398,88 @@ bool AMDGPUPromoteAllocaImpl::run(Function &F, bool PromoteToLDS) {
: (MaxVGPRs * 32)) /
VGPRBudgetRatio;
- std::vector<AllocaAnalysis> Allocas;
+ SmallMapVector<AllocaInst *, AllocaAnalysis, 4> AllocaAnalysisMap;
for (Instruction &I : F.getEntryBlock()) {
- if (AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
- // Array allocations are probably not worth handling, since an allocation
- // of the array type is the canonical form.
- if (!AI->isStaticAlloca() || AI->isArrayAllocation())
- continue;
+ auto *AI = dyn_cast<AllocaInst>(&I);
+ // Array allocations are probably not worth handling, since an allocation
+ // of the array type is the canonical form.
+ if (!AI || !AI->isStaticAlloca() || AI->isArrayAllocation())
+ continue;
+ LLVM_DEBUG(dbgs() << "Analyzing: " << *AI << '\n');
+ AllocaAnalysis AA{AI};
+ if (!collectAllocaUses(AA))
+ continue;
+ AllocaAnalysisMap.insert({AI, std::move(AA)});
+ }
- LLVM_DEBUG(dbgs() << "Analyzing: " << *AI << '\n');
+ std::vector<AllocaAnalysis> Allocas;
+ for (auto &AA : AllocaAnalysisMap.values()) {
+ if (AA.Uses.empty())
+ continue;
- AllocaAnalysis AA{AI};
- if (collectAllocaUses(AA)) {
- analyzePromoteToVector(AA);
- if (PromoteToLDS)
- analyzePromoteToLDS(AA);
- if (AA.Vector.Ty || AA.LDS.Enable) {
- scoreAlloca(AA);
- Allocas.push_back(std::move(AA));
- }
+ bool Promotable = true;
+ SmallVector<AllocaInst *> Worklist;
+ LLVM_DEBUG(dbgs() << "Process leader alloca " << *AA.Alloca << '\n');
+ Worklist.append(AA.Links);
+ // Pull the information from links into the leader alloca.
+ while (!Worklist.empty()) {
+ auto *CurLink = Worklist.pop_back_val();
+ auto *LinkIter = AllocaAnalysisMap.find(CurLink);
----------------
arsenm wrote:
This isn't really a pointer?
https://github.com/llvm/llvm-project/pull/221870
More information about the llvm-commits
mailing list