This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix v_swap_b32 formation on physical registers
ClosedPublic

Authored by foad on Apr 29 2021, 9:55 AM.

Details

Summary

As explained in the comments, matchSwap matches:

mov t, x
mov x, y
// mov y, t

and turns it into:

mov t, x (t is potentially dead and move eliminated)
v_swap_b32 x, y

On physical registers we don't have full use-def chains so the check
for T being live-out was not working properly with subregs/superregs.

Diff Detail

Event Timeline

foad created this revision.Apr 29 2021, 9:55 AM
foad requested review of this revision.Apr 29 2021, 9:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2021, 9:55 AM

We don't need to rely on kill flags (and in fact should not, since they are semi-deprecated). We should be using liveness scans starting from the bottom of the block which do not need kill flags

foad added a comment.Apr 29 2021, 10:11 AM

We don't need to rely on kill flags (and in fact should not, since they are semi-deprecated). We should be using liveness scans starting from the bottom of the block which do not need kill flags

I'm not relying on the kill flag being present for correctness, I'm just taking advantage of it if it does happen to be there (and assuming that it is correct if it is present). If kill flags are not present then I guess you'd need to run MachineDCE again afterwards to clean up.

llvm/lib/Target/AMDGPU/SIShrinkInstructions.cpp
580–583

Does this part make sense? I am really not too sure what kind of liveness information we can rely on here for virtual and/or physical registers.

We don't need to rely on kill flags (and in fact should not, since they are semi-deprecated). We should be using liveness scans starting from the bottom of the block which do not need kill flags

I'm not relying on the kill flag being present for correctness, I'm just taking advantage of it if it does happen to be there (and assuming that it is correct if it is present). If kill flags are not present then I guess you'd need to run MachineDCE again afterwards to clean up.

I don't mean rely on for correctness, I mean use at all. Ideally we should be working to eliminate dependence on kill flags for optimizations.

foad updated this revision to Diff 341576.Apr 29 2021, 10:44 AM

Don't use kill flags.

foad edited the summary of this revision. (Show Details)Apr 29 2021, 10:44 AM
foad added a comment.Apr 29 2021, 11:15 AM

We should be using liveness scans starting from the bottom of the block which do not need kill flags

To do this efficiently I guess the whole pass needs to be changed to work bottom-up in each basic block. I'd prefer to leave that for a separate patch.

This revision is now accepted and ready to land.Apr 29 2021, 12:26 PM
This revision was landed with ongoing or failed builds.Apr 29 2021, 12:53 PM
This revision was automatically updated to reflect the committed changes.

You can use the kill flags for now but it is something to migrate away from