From dbd42401305b45e4a2854d24a1987d0f01b75754 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Thu, 29 Jan 2026 19:57:16 +0000 Subject: [PATCH] [AMDGPU] Fix DEALLOC_VGPRS in the presence of spills to scratch (#178461) --- llvm/lib/Target/AMDGPU/SIInstrInfo.cpp | 9 +++++---- llvm/test/CodeGen/AMDGPU/release-vgprs-spill.ll | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp index 6e95f418b882..fb82598709aa 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp +++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp @@ -4482,14 +4482,15 @@ bool SIInstrInfo::mayAccessScratch(const MachineInstr &MI) const { if ((!isFLAT(MI) || isFLATGlobal(MI)) && !isBUF(MI)) return false; - // If scratch is not initialized, we can never access it. - if (MI.getMF()->getFunction().hasFnAttribute("amdgpu-no-flat-scratch-init")) - return false; - // SCRATCH instructions always access scratch. if (isFLATScratch(MI)) return true; + // If FLAT_SCRATCH registers are not initialized, we can never access scratch + // via the aperture. + if (MI.getMF()->getFunction().hasFnAttribute("amdgpu-no-flat-scratch-init")) + return false; + // If there are no memory operands then conservatively assume the flat // operation may access scratch. if (MI.memoperands_empty()) diff --git a/llvm/test/CodeGen/AMDGPU/release-vgprs-spill.ll b/llvm/test/CodeGen/AMDGPU/release-vgprs-spill.ll index 2d204e8ef571..3d41dddef1a6 100644 --- a/llvm/test/CodeGen/AMDGPU/release-vgprs-spill.ll +++ b/llvm/test/CodeGen/AMDGPU/release-vgprs-spill.ll @@ -3,7 +3,7 @@ ; This function uses scratch_store to spill some values to the stack. While ; these stores are potentially outstanding it should not send the DEALLOC_VGPRS -; message. FIXME. +; message. define amdgpu_kernel void @f(ptr %ptr, i32 %arg) "amdgpu-flat-work-group-size"="64,64" { ; CHECK-LABEL: f: @@ -32,8 +32,6 @@ define amdgpu_kernel void @f(ptr %ptr, i32 %arg) "amdgpu-flat-work-group-size"=" ; CHECK-NEXT: s_waitcnt vmcnt(0) ; CHECK-NEXT: global_store_b32 v[0:1], v2, off ; CHECK-NEXT: .LBB0_2: ; %false -; CHECK-NEXT: s_nop 0 -; CHECK-NEXT: s_sendmsg sendmsg(MSG_DEALLOC_VGPRS) ; CHECK-NEXT: s_endpgm %tid = call i32 @llvm.amdgcn.workitem.id.x() %gep = getelementptr i32, ptr %ptr, i32 %tid