[llvm] AMDGPU: Delay value replacement in PromoteAlloca (PR #186944)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 19 03:23:49 PDT 2026
================
@@ -420,14 +460,23 @@ bool AMDGPUPromoteAllocaImpl::run(Function &F, bool PromoteToLDS) {
bool Changed = false;
SetVector<IntrinsicInst *> DeferredIntrs;
+ ValueReplacer VR;
+ SmallVector<Instruction *> ToBeErased;
+
for (AllocaAnalysis &AA : Allocas) {
if (AA.Vector.Ty) {
std::optional<TypeSize> Size = AA.Alloca->getAllocationSize(*DL);
assert(Size); // Expected to succeed on non-array alloca.
const unsigned AllocaCost = Size->getFixedValue() * 8;
// First, check if we have enough budget to vectorize this alloca.
if (AllocaCost <= VectorizationBudget) {
- promoteAllocaToVector(AA);
+ promoteAllocaToVector(AA, VR);
+
+ VR.postErase(AA.Vector.Worklist);
+ // Append in reverse order so that further users would be erased first.
+ VR.postErase(reverse(AA.Vector.UsersToRemove));
----------------
jmmartinez wrote:
Why do we have to call `reverse` in here? We're already calling `dropDropableUsers`, so we could erase the elements in any order we want since the users should be empty.
---
If we find out that we can remove `reverse`, we would be able to have a single `postErase` method taking an `ArrayRef` (a single element can convert to `ArrayRef` if I recall correctly).
https://github.com/llvm/llvm-project/pull/186944
More information about the llvm-commits
mailing list