This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Save all lanes for reserved VGPRs
ClosedPublic

Authored by sebastian-ne on Feb 3 2021, 5:30 AM.

Details

Summary

When SGPRs are spilled to VGPRs, they can overwrite any lane. We need
to preserve the value of inactive lanes in function calls, so we save
the register even if it is marked as caller saved.

Also, teach buildPrologSpill to work when no registers are free like in
CodeGen/AMDGPU/pei-scavenge-vgpr-spill.mir and update the comment on
findScratchNonCalleeSaveRegister as it is not used anymore to realign
the stack pointer since D95865.

Diff Detail

Event Timeline

sebastian-ne created this revision.Feb 3 2021, 5:30 AM
sebastian-ne requested review of this revision.Feb 3 2021, 5:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2021, 5:30 AM
arsenm added a comment.Feb 3 2021, 6:04 AM

Can we avoid spilling the clobbered registers if we know the function doesn't use whole wave mode?

This should only spill VGPRs that are used for SGPR→VGPR spills. These spills can overwrite VGPRs from inactive lanes. Other caller-save registers should not be saved by the callee.
For whole wave mode, I still need to write a patch. It should work similar like here.

In the end, new saves are inserted for SGPR→VGPR spills if the VGPR is caller-save (callee-save VGPRs are already saved)
and WWM reserved registers.

Clobbered caller-save registers that are neither used for SGPR spills nor WWM are not saved in the callee.

arsenm accepted this revision.Feb 3 2021, 8:08 AM
This revision is now accepted and ready to land.Feb 3 2021, 8:08 AM
arsenm added a comment.Feb 3 2021, 8:09 AM

Do probably need to broaden this in cases where the readlane/writelane intrinsics are used, but that's a separate issue

This revision was landed with ongoing or failed builds.Feb 4 2021, 1:08 AM
This revision was automatically updated to reflect the committed changes.