This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Allow architected SGPRs for workgroup IDs
ClosedPublic

Authored by cdevadas on Feb 10 2023, 12:56 AM.

Details

Summary

Some subtargets use architected SGPRs for workgroup
IDs instead of the regular SGPRs. This patch enables
the support for the same and is guarded under the
subtarget feature FeatureArchitectedSGPRs.

Diff Detail

Event Timeline

cdevadas created this revision.Feb 10 2023, 12:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 12:56 AM
cdevadas requested review of this revision.Feb 10 2023, 12:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 12:56 AM
foad added inline comments.Feb 10 2023, 1:45 AM
llvm/test/CodeGen/AMDGPU/workgroup-id-in-arch-sgprs.ll
27

Why are all these stores volatile?

54

Doesn't this value need to be ANDed with 0xffff?

cdevadas added inline comments.Feb 10 2023, 2:52 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
2260

Also, should I guard this check with HasArchitectedSGPRS?
The numPreloaded regular SGPRs will vary if TTMP registers are used for workgroup IDs.

llvm/test/CodeGen/AMDGPU/workgroup-id-in-arch-sgprs.ll
27

Will change.

54

If there is no WorkGroupIDZ, I thought I can skip that part.
Just like the packedTID here.
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/SIISelLowering.cpp#L1934

foad added inline comments.Feb 10 2023, 3:05 AM
llvm/test/CodeGen/AMDGPU/workgroup-id-in-arch-sgprs.ll
54

I don't understand. How do you know "there is no WorkGroupIDZ"? Just because this function does not call @llvm.amdgcn.workgroup.id.z?

cdevadas added inline comments.Feb 10 2023, 3:11 AM
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
707

The hasWorkGroupIDZ() will be set to 1 if there is a workgroup IDZ used. Otherwise, this function would return false.
The WorkGroupIDX, WorkGroupIDY, and WorkGroupIDZ fields in the MachineFunctionInfo would have set/reset it by now.

foad added inline comments.Feb 10 2023, 4:10 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
2260
llvm/lib/Target/AMDGPU/SIMachineFunctionInfo.h
707

OK, I understand now, if the function does not call @llvm.amdgcn.workgroup.id.z then the compiler will not set COMPUTE_PGM_RSRC2:TGID_Z_EN so the hardware will initialize the top half of TTMP7 to 0.

cdevadas updated this revision to Diff 496868.Feb 13 2023, 1:29 AM

Adjusted NumRequiredSystemSGPRs before force initializing the 16 input SGPRs.

foad added inline comments.Feb 13 2023, 3:12 AM
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
2200

It is not at all clear how hasArchitectedSGPRs and hasUserSGPRInit16Bug should interact. Instead of guessing, how about asserting !HasArchitectedSGPRs here unless/until there is an ASIC that has both features?

cdevadas updated this revision to Diff 496956.Feb 13 2023, 6:39 AM

Added an assertion as per review comment.

foad accepted this revision.Feb 13 2023, 6:53 AM

LGTM, thanks.

This revision is now accepted and ready to land.Feb 13 2023, 6:53 AM
This revision was automatically updated to reflect the committed changes.