This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Do not reserve any VGPR for SGPR spills
ClosedPublic

Authored by kerbowa on Dec 10 2021, 1:45 PM.

Details

Summary

After the split register allocation changes in eebe841a47cb it is no
longer necessary to reserve a VGPR before RA. This can also create bugs
when IPRA is enabled since we cannot predict that a called function may
not reserve any register if it does not have any SGPR spills. If that
happens those functions may override reserved registers that are
normally callee saved. Added a test to show this.

Fixes: SWDEV-309900

Diff Detail

Event Timeline

kerbowa created this revision.Dec 10 2021, 1:45 PM
kerbowa requested review of this revision.Dec 10 2021, 1:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 10 2021, 1:45 PM
arsenm added inline comments.Dec 10 2021, 1:54 PM
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
1331–1333

I don't see why you're changing this, this is still an issue?

arsenm added inline comments.Dec 10 2021, 1:56 PM
llvm/test/CodeGen/AMDGPU/sgpr-spills-split-regalloc.ll
296

Also add a tail call case?

kerbowa added inline comments.Dec 10 2021, 2:04 PM
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
1331–1333

With the change, we are being more conservative.

kerbowa updated this revision to Diff 393599.Dec 10 2021, 2:33 PM

Add tail call test.

arsenm added inline comments.Dec 10 2021, 3:02 PM
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
1331–1333

But why, I don't see the connection to eliminating the reserved register

sebastian-ne added inline comments.
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.cpp
301

Typo: spilit

kerbowa updated this revision to Diff 396623.Dec 30 2021, 12:12 AM

Update WillHaveFP prediction.

kerbowa added inline comments.
llvm/lib/Target/AMDGPU/SIFrameLowering.cpp
1331–1333

We would usually reserve a register so this check was essentially always true if the function had calls. I've updated the condition since we will have a FP if there are any CSR SGPR spills too.

kerbowa updated this revision to Diff 398512.Jan 9 2022, 10:20 PM

Remove dead code.

arsenm accepted this revision.Jan 10 2022, 9:32 AM
This revision is now accepted and ready to land.Jan 10 2022, 9:32 AM
ruiling added inline comments.Jan 10 2022, 5:33 PM
llvm/test/CodeGen/AMDGPU/sgpr-spills-split-regalloc.ll
212

I don't quite understand the patch, but this is an obvious regression. the generated code is pretty bad for this case. Is there any possible way to still use vgpr for sgpr spill for such kind of case?

arsenm added inline comments.Jan 10 2022, 5:38 PM
llvm/test/CodeGen/AMDGPU/sgpr-spills-split-regalloc.ll
212

It's -O0 so we basically don't care about the code quality at all, plus it's a torture test.

Since the register allocation is split now, it will try to use a VGPR if it can find a free one. With the current limitation that we have to reserve VGPRs for SGPR spills, and that the test heavily constrained the available VGPRs, it won't find a free one to use.

This revision was automatically updated to reflect the committed changes.