llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.12k stars 12.01k forks source link

[AMDGPU] No available SGPR for CSR spill stores #113782

Open shiltian opened 2 weeks ago

shiltian commented 2 weeks ago

In emitCSRSpillStores, a non-callee-saved SGPR is required to save exec, which limits us to using SGPR0 through SGPR29. Currently, we assume that one is always available; however, this isn’t always the case, as SGPR0 to SGPR29 are also used for inreg argument passing.

https://github.com/llvm/llvm-project/blob/3b7d788ff22b8aa22634b927faf01da12bece496/llvm/lib/Target/AMDGPU/SIFrameLowering.cpp#L966

If there are enough inreg arguments, no SGPR is available, leading to a compiler crash. The following example demonstrates this issue.

; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 %s -o -

declare hidden void @external_void_func_a15i32_inreg([16 x i32] inreg)

define void @test_call_external_void_func_a15i32_inreg([16 x i32] inreg %arg0) {
  call void @external_void_func_a15i32_inreg([16 x i32] inreg %arg0)
  ret void
}
llvmbot commented 2 weeks ago

@llvm/issue-subscribers-backend-amdgpu

Author: Shilei Tian (shiltian)

If there are enough number of SGPR arguments, they will be spilled into VGPRs. However, we don’t reserve one SGPR to handle `exec` for the spilling.
shiltian commented 1 week ago

It seems we can’t simply perform another SGPR-to-VGPR spill here, as we’re effectively already doing it. It appears we’ll need to reserve two SGPRs specifically for this purpose and disable them using an attribute.