This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Add a regclass flag for scalar registers
ClosedPublic

Authored by cdevadas on Sep 20 2021, 1:27 AM.

Details

Summary

Along with vector RC flags, this scalar flag will
make various regclass queries like isVGPR more
accurate.

Regclasses other than vectors are currently set
with the new flag even though certain unallocatable
classes aren't truly scalars. It would be ok as long
as they remain unallocatable.

Diff Detail

Event Timeline

cdevadas created this revision.Sep 20 2021, 1:27 AM
cdevadas requested review of this revision.Sep 20 2021, 1:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2021, 1:27 AM
rampitec added inline comments.Sep 20 2021, 2:00 PM
llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
1173

Why do you need to change this?

llvm/lib/Target/AMDGPU/SIRegisterInfo.td
138

TTMP is scalar.

794

It does not have SGPRs.

cdevadas added inline comments.Sep 20 2021, 7:37 PM
llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
1173

I assumed that check is specifically for VS_32/VS_64 classes. Isn't it the case?

llvm/lib/Target/AMDGPU/SIRegisterInfo.td
138

I will use another reference.

794

I tried to associate them with the closest regtype (either VGPR or SGPR).
I can remove it.

rampitec added inline comments.Sep 21 2021, 11:28 AM
llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
1173

SDWA cannot use SGPR operand, the original instruction can. So if the operand is not a VGPR it should bail. isVGPRClass() is correct here.

llvm/lib/Target/AMDGPU/SIRegisterInfo.td
794

It has VGPRs and nothing more.

cdevadas added inline comments.Sep 21 2021, 11:45 PM
llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
1173

The check here is not to bail out, I guess, but to legalize the Op.
The code here https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp#L1182
changes the operands of SGPRs to VGPRs by introducing a copy. (For gxf9 we can have at most 1 SGPR)

Look at this instruction:
%29:vgpr_32 = V_MIN_I16_sdwa 1, %12:sreg_32, 1, %22:sreg_32, 0, 1, 0, 1, 1,
The 2nd and 4th operands of this SDWA instruction are of VS_32 type as per Desc. For gfx9, the 4th operand should be changed to VGPR class.
The VS_32 class earlier contained only VGPR flag and it was ok to have isVGPRClass query to identify it. After introducing SGPR flag, we could use hasVGPRs query instead. But to make the check more precise, I used the combined VS class.

Otherwise, MIR verifier reports an error.

rampitec added inline comments.Sep 22 2021, 10:44 AM
llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp
1173

Thanks. Understood.

cdevadas updated this revision to Diff 374595.Sep 23 2021, 9:58 AM
cdevadas edited the summary of this revision. (Show Details)

Removed scalar flag from VRegOrLds_32.

rampitec added inline comments.Sep 23 2021, 11:21 AM
llvm/lib/Target/AMDGPU/SIRegisterInfo.td
138

I think you can just drop the comment. There does not seem to be a TODO here.
Otherwise LGTM.

cdevadas updated this revision to Diff 374721.Sep 23 2021, 8:55 PM

Removed unwanted comments.

This revision is now accepted and ready to land.Sep 24 2021, 12:43 AM
cdevadas updated this revision to Diff 390949.Dec 1 2021, 1:36 AM

Rebase after D110762

This revision was automatically updated to reflect the committed changes.