llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AMDGPU] Add LDS-backed VGPR spill/fill using DS ADDTID

Open keshavvinayak01 opened this issue 4 months ago • 4 comments

AMDGPU targets starting with GFX9 support DS_{READ,WRITE}_ADDTID_B32, which provide per-lane LDS addressing without requiring an address VGPR. LLVM already models these instructions and handles the GFX9 M0-write hazard, but normal codegen does not use this. VGPR spills that cannot use the existing VGPR-to-AGPR mechanism are currently lowered to scratch memory.

The proposal is to add an LDS-backed destination for eligible VGPR spill/fill operations using the ADDTID instructions. The implementation should:

  • Allocate spill storage after existing static LDS.
  • Use only LDS that does not reduce current occupancy.
  • Correctly manage M0, local-address-space memory operands, CFI, and resource metadata.
  • Preserve scratch spilling as a fallback.

Previous LLVM attempt: https://reviews.llvm.org/D130784 Related Mesa ACO implementation: https://gitlab.freedesktop.org/mesa/mesa/-/commit/133ef9f94b561ff3b0e8ed0dbb85a9e2fa024ac3

keshavvinayak01 avatar Jul 23 '26 13:07 keshavvinayak01

@llvm/issue-subscribers-backend-amdgpu

Author: Keshav Vinayak Jha (keshavvinayak01)

AMDGPU targets starting with GFX9 support `DS_{READ,WRITE}_ADDTID_B32`, which provide per-lane LDS addressing without requiring an address VGPR. LLVM already models these instructions and handles the GFX9 M0-write hazard, but normal codegen does not use this. VGPR spills that cannot use the existing VGPR-to-AGPR mechanism are currently lowered to scratch memory.

The proposal is to add an LDS-backed destination for eligible VGPR spill/fill operations using the ADDTID instructions. The implementation should:

  • Allocate spill storage after existing static LDS.
  • Use only LDS that does not reduce current occupancy.
  • Correctly manage M0, local-address-space memory operands, CFI, and resource metadata.
  • Preserve scratch spilling as a fallback.

Previous LLVM attempt: https://reviews.llvm.org/D130784 Related Mesa ACO implementation: https://gitlab.freedesktop.org/mesa/mesa/-/commit/133ef9f94b561ff3b0e8ed0dbb85a9e2fa024ac3

I believe @piotrAMD had old patches for this

arsenm avatar Jul 23 '26 14:07 arsenm

@piotrAMD I see the commit https://github.com/GPUOpen-Drivers/llvm-project/commit/34ce019fab8185ab3083a8d60c10eb1cb973b58d but nothing here, do you think you can add that commit here and close it or are we missing something? Also, I see that the committed code is the prototype and didn't actually address the comments in the original discussion. Is this something I can take up and work on?

keshavvinayak01 avatar Jul 23 '26 15:07 keshavvinayak01

The current thinking is that the proper support for this is dependent on Early Register Spilling going in first (https://github.com/llvm/llvm-project/pull/171523). @kmitropoulou

piotrAMD avatar Jul 29 '26 08:07 piotrAMD