[llvm] 2b522e0 - Reapply "[AMDGPU] Fix excessive stack usage in SIInsertWaitcnts::run (#134835)" (#174215) (#177338)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 22 03:25:12 PST 2026


Author: Jay Foad
Date: 2026-01-22T11:25:08Z
New Revision: 2b522e0b094acbc1e911b1cfb14a47a0ff91931a

URL: https://github.com/llvm/llvm-project/commit/2b522e0b094acbc1e911b1cfb14a47a0ff91931a
DIFF: https://github.com/llvm/llvm-project/commit/2b522e0b094acbc1e911b1cfb14a47a0ff91931a.diff

LOG: Reapply "[AMDGPU] Fix excessive stack usage in SIInsertWaitcnts::run (#134835)" (#174215) (#177338)

This reverts commit 0dd03598dca91c93c74b94a714c38a4ffad0ed1c.

Apparently the stack usage on Windows was still large enough to cause
problems for some DirectX games.

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
index f0c2b9f8dde27..01331650fca6f 100644
--- a/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp
@@ -3343,10 +3343,15 @@ bool SIInsertWaitcnts::run(MachineFunction &MF) {
         else
           *Brackets = *BI.Incoming;
       } else {
-        if (!Brackets)
+        if (!Brackets) {
           Brackets = std::make_unique<WaitcntBrackets>(this);
-        else
-          *Brackets = WaitcntBrackets(this);
+        } else {
+          // Reinitialize in-place. N.B. do not do this by assigning from a
+          // temporary because the WaitcntBrackets class is large and it could
+          // cause this function to use an unreasonable amount of stack space.
+          Brackets->~WaitcntBrackets();
+          new (Brackets.get()) WaitcntBrackets(this);
+        }
       }
 
       Modified |= insertWaitcntInBlock(MF, *MBB, *Brackets);


        


More information about the llvm-commits mailing list