[llvm] Limit Alloca->LDS promotion based on speculations as to eventual register pressure (PR #152814)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 14 19:15:49 PDT 2025
================
@@ -1471,9 +1485,87 @@ bool AMDGPUPromoteAllocaImpl::hasSufficientLocalMem(const Function &F) {
return true;
}
+size_t AMDGPUPromoteAllocaImpl::getSGPRPressureEstimate(AllocaInst &I) {
+ Function &F = *I.getFunction();
+ size_t MaxLive = 0;
+ for (BasicBlock *BB : post_order(&F)) {
+ if (SGPRLiveIns.count(BB))
+ continue;
+
+ std::unordered_set<Instruction *> CurrentlyLive;
+ for (BasicBlock *SuccBB : successors(BB))
+ if (SGPRLiveIns.count(SuccBB))
+ for (const auto &R : SGPRLiveIns[SuccBB])
+ CurrentlyLive.insert(R);
+
+ for (auto RIt = BB->rbegin(); RIt != BB->rend(); RIt++) {
+ if (&*RIt == &I)
+ return MaxLive;
+
+ MaxLive = std::max(MaxLive, CurrentlyLive.size());
+
+ for (auto &Op : RIt->operands())
+ if (!Op.get()->getType()->isVectorTy())
+ if (Instruction *U = dyn_cast<Instruction>(Op))
+ CurrentlyLive.insert(U);
+
+ if (!RIt->getType()->isVectorTy())
+ CurrentlyLive.erase(&*RIt);
+ }
+
+ SGPRLiveIns[BB] = CurrentlyLive;
+ }
+
+ llvm_unreachable("Woops, we fell off the edge of the world. Bye bye.");
+}
+
+size_t AMDGPUPromoteAllocaImpl::getVGPRPressureEstimate(AllocaInst &I) {
+ Function &F = *I.getParent()->getParent();
+ size_t MaxLive = 0;
+ for (BasicBlock *BB : post_order(&F)) {
+ if (VGPRLiveIns.count(BB))
+ continue;
+
+ std::unordered_set<Instruction *> CurrentlyLive;
+ for (BasicBlock *SuccBB : successors(BB))
+ if (VGPRLiveIns.count(SuccBB))
+ for (const auto &R : VGPRLiveIns[SuccBB])
+ CurrentlyLive.insert(R);
+
+ for (auto RIt = BB->rbegin(); RIt != BB->rend(); RIt++) {
+ if (&*RIt == &I)
+ return MaxLive;
+
+ MaxLive = std::max(MaxLive, CurrentlyLive.size());
+
+ for (auto &Op : RIt->operands())
+ if (Op.get()->getType()->isVectorTy())
+ if (Instruction *U = dyn_cast<Instruction>(Op))
+ CurrentlyLive.insert(U);
+
+ if (RIt->getType()->isVectorTy())
----------------
arsenm wrote:
No, but the type has nothing to do with it. We don't have any real / precise attempts pressure heuristics in IR
https://github.com/llvm/llvm-project/pull/152814
More information about the llvm-commits
mailing list