-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[AMDGPU] Rework architected SGPRs implementation #79001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,8 +107,8 @@ SIMachineFunctionInfo::SIMachineFunctionInfo(const Function &F, | |
MayNeedAGPRs = false; // We will select all MAI with VGPR operands. | ||
} | ||
|
||
if (!AMDGPU::isGraphics(CC) || | ||
(CC == CallingConv::AMDGPU_CS && ST.hasArchitectedSGPRs())) { | ||
if (!AMDGPU::isGraphics(CC) || CC == CallingConv::AMDGPU_CS || | ||
ST.hasArchitectedSGPRs()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks redundant as this patch always allocate the TTMP* for subtargets with architectedSGPR enabled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I need |
||
if (IsKernel || !F.hasFnAttribute("amdgpu-no-workgroup-id-x")) | ||
WorkGroupIDX = true; | ||
|
||
|
@@ -169,6 +169,15 @@ SIMachineFunctionInfo::SIMachineFunctionInfo(const Function &F, | |
VGPRForAGPRCopy = | ||
AMDGPU::VGPR_32RegClass.getRegister(ST.getMaxNumVGPRs(F) - 1); | ||
} | ||
|
||
if (STI->hasArchitectedSGPRs()) { | ||
ArgInfo.ArchitectedWorkGroupIDX = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's OK for the lowering to directly consume the hardcoded register numbers There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean not go via these |
||
ArgDescriptor::createRegister(AMDGPU::TTMP9); | ||
ArgInfo.ArchitectedWorkGroupIDY = ArgDescriptor::createRegister( | ||
AMDGPU::TTMP7, WorkGroupIDZ ? 0xFFFFu : ~0u); | ||
ArgInfo.ArchitectedWorkGroupIDZ = | ||
ArgDescriptor::createRegister(AMDGPU::TTMP7, 0xFFFF0000u); | ||
} | ||
} | ||
|
||
MachineFunctionInfo *SIMachineFunctionInfo::clone( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,8 @@ define amdgpu_ps i32 @test_ps() #1 { | |
} | ||
|
||
; GCN-LABEL: {{^}}test_cs: | ||
; GCN: s_mov_b64 s[4:5], s[0:1] | ||
; GCN: buffer_store_dword v{{[0-9]+}}, off, s[4:7], 0 offset:4 | ||
; GCN: s_mov_b64 s[8:9], s[0:1] | ||
; GCN: buffer_store_dword v{{[0-9]+}}, off, s[8:11], 0 offset:4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this expected? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I guess I've broken something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following change? It now enables workgroup IDs for AMDGPU_CS always.
|
||
; GCN: s_load_dword s0, s[0:1], 0x0 | ||
define amdgpu_cs i32 @test_cs() #1 { | ||
%alloca = alloca i32, addrspace(5) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=amdgcn-amd-hsa -mcpu=gfx900 -mattr=+architected-sgprs --verify-machineinstrs < %s | FileCheck -check-prefix=GFX9-SDAG %s | ||
; RUN: llc -mtriple=amdgcn-amd-hsa -mcpu=gfx900 -mattr=+architected-sgprs -global-isel --verify-machineinstrs < %s | FileCheck -check-prefix=GFX9-GISEL %s | ||
|
||
define amdgpu_kernel void @workgroup_ids_kernel() { | ||
; GFX9-SDAG-LABEL: workgroup_ids_kernel: | ||
; GFX9-SDAG: ; %bb.0: ; %.entry | ||
; GFX9-SDAG-NEXT: s_lshr_b32 s2, ttmp7, 16 | ||
; GFX9-SDAG-NEXT: s_and_b32 s1, ttmp7, 0xffff | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v0, ttmp9 | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v1, s1 | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v2, s2 | ||
; GFX9-SDAG-NEXT: buffer_store_dwordx3 v[0:2], off, s[0:3], 0 | ||
; GFX9-SDAG-NEXT: s_endpgm | ||
; | ||
; GFX9-GISEL-LABEL: workgroup_ids_kernel: | ||
; GFX9-GISEL: ; %bb.0: ; %.entry | ||
; GFX9-GISEL-NEXT: s_mov_b32 s0, ttmp9 | ||
; GFX9-GISEL-NEXT: s_and_b32 s1, ttmp7, 0xffff | ||
; GFX9-GISEL-NEXT: s_lshr_b32 s2, ttmp7, 16 | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v0, s0 | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v1, s1 | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v2, s2 | ||
; GFX9-GISEL-NEXT: buffer_store_dwordx3 v[0:2], off, s[0:3], 0 | ||
; GFX9-GISEL-NEXT: s_endpgm | ||
.entry: | ||
%idx = call i32 @llvm.amdgcn.workgroup.id.x() | ||
%idy = call i32 @llvm.amdgcn.workgroup.id.y() | ||
%idz = call i32 @llvm.amdgcn.workgroup.id.z() | ||
%ielemx = insertelement <3 x i32> undef, i32 %idx, i64 0 | ||
%ielemy = insertelement <3 x i32> %ielemx, i32 %idy, i64 1 | ||
%ielemz = insertelement <3 x i32> %ielemy, i32 %idz, i64 2 | ||
call void @llvm.amdgcn.raw.ptr.buffer.store.v3i32(<3 x i32> %ielemz, ptr addrspace(8) undef, i32 0, i32 0, i32 0) | ||
ret void | ||
} | ||
|
||
define amdgpu_kernel void @caller() { | ||
; GFX9-SDAG-LABEL: caller: | ||
; GFX9-SDAG: ; %bb.0: | ||
; GFX9-SDAG-NEXT: s_mov_b32 s36, SCRATCH_RSRC_DWORD0 | ||
; GFX9-SDAG-NEXT: s_mov_b32 s37, SCRATCH_RSRC_DWORD1 | ||
; GFX9-SDAG-NEXT: s_mov_b32 s38, -1 | ||
; GFX9-SDAG-NEXT: s_mov_b32 s39, 0xe00000 | ||
; GFX9-SDAG-NEXT: s_add_u32 s36, s36, s8 | ||
; GFX9-SDAG-NEXT: s_addc_u32 s37, s37, 0 | ||
; GFX9-SDAG-NEXT: s_add_u32 s8, s4, 36 | ||
; GFX9-SDAG-NEXT: s_addc_u32 s9, s5, 0 | ||
; GFX9-SDAG-NEXT: s_getpc_b64 s[4:5] | ||
; GFX9-SDAG-NEXT: s_add_u32 s4, s4, callee@gotpcrel32@lo+4 | ||
; GFX9-SDAG-NEXT: s_addc_u32 s5, s5, callee@gotpcrel32@hi+12 | ||
; GFX9-SDAG-NEXT: s_load_dwordx2 s[14:15], s[4:5], 0x0 | ||
; GFX9-SDAG-NEXT: s_mov_b64 s[10:11], s[6:7] | ||
; GFX9-SDAG-NEXT: v_lshlrev_b32_e32 v2, 20, v2 | ||
; GFX9-SDAG-NEXT: v_lshlrev_b32_e32 v1, 10, v1 | ||
; GFX9-SDAG-NEXT: s_mov_b64 s[4:5], s[0:1] | ||
; GFX9-SDAG-NEXT: s_mov_b64 s[6:7], s[2:3] | ||
; GFX9-SDAG-NEXT: s_mov_b64 s[0:1], s[36:37] | ||
; GFX9-SDAG-NEXT: s_mov_b32 s12, ttmp9 | ||
; GFX9-SDAG-NEXT: v_or3_b32 v31, v0, v1, v2 | ||
; GFX9-SDAG-NEXT: s_mov_b64 s[2:3], s[38:39] | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v0, ttmp9 | ||
; GFX9-SDAG-NEXT: s_mov_b32 s32, 0 | ||
; GFX9-SDAG-NEXT: s_waitcnt lgkmcnt(0) | ||
; GFX9-SDAG-NEXT: s_swappc_b64 s[30:31], s[14:15] | ||
; GFX9-SDAG-NEXT: s_endpgm | ||
; | ||
; GFX9-GISEL-LABEL: caller: | ||
; GFX9-GISEL: ; %bb.0: | ||
; GFX9-GISEL-NEXT: s_mov_b32 s36, SCRATCH_RSRC_DWORD0 | ||
; GFX9-GISEL-NEXT: s_mov_b32 s37, SCRATCH_RSRC_DWORD1 | ||
; GFX9-GISEL-NEXT: s_mov_b32 s38, -1 | ||
; GFX9-GISEL-NEXT: s_mov_b32 s39, 0xe00000 | ||
; GFX9-GISEL-NEXT: s_add_u32 s36, s36, s8 | ||
; GFX9-GISEL-NEXT: s_addc_u32 s37, s37, 0 | ||
; GFX9-GISEL-NEXT: s_add_u32 s8, s4, 36 | ||
; GFX9-GISEL-NEXT: s_addc_u32 s9, s5, 0 | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[14:15], s[0:1] | ||
; GFX9-GISEL-NEXT: s_getpc_b64 s[0:1] | ||
; GFX9-GISEL-NEXT: s_add_u32 s0, s0, callee@gotpcrel32@lo+4 | ||
; GFX9-GISEL-NEXT: s_addc_u32 s1, s1, callee@gotpcrel32@hi+12 | ||
; GFX9-GISEL-NEXT: s_load_dwordx2 s[16:17], s[0:1], 0x0 | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[10:11], s[6:7] | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[6:7], s[2:3] | ||
; GFX9-GISEL-NEXT: v_lshlrev_b32_e32 v1, 10, v1 | ||
; GFX9-GISEL-NEXT: v_lshlrev_b32_e32 v2, 20, v2 | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[0:1], s[36:37] | ||
; GFX9-GISEL-NEXT: s_mov_b32 s12, ttmp9 | ||
; GFX9-GISEL-NEXT: v_or3_b32 v31, v0, v1, v2 | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v0, ttmp9 | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[2:3], s[38:39] | ||
; GFX9-GISEL-NEXT: s_mov_b64 s[4:5], s[14:15] | ||
; GFX9-GISEL-NEXT: s_mov_b32 s32, 0 | ||
; GFX9-GISEL-NEXT: s_waitcnt lgkmcnt(0) | ||
; GFX9-GISEL-NEXT: s_swappc_b64 s[30:31], s[16:17] | ||
; GFX9-GISEL-NEXT: s_endpgm | ||
%idx = call i32 @llvm.amdgcn.workgroup.id.x() | ||
call void @callee(i32 %idx) #0 | ||
ret void | ||
} | ||
|
||
declare void @callee(i32) #0 | ||
|
||
define void @workgroup_ids_device_func(ptr addrspace(1) %outx, ptr addrspace(1) %outy, ptr addrspace(1) %outz) { | ||
; GFX9-SDAG-LABEL: workgroup_ids_device_func: | ||
; GFX9-SDAG: ; %bb.0: | ||
; GFX9-SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v6, ttmp9 | ||
; GFX9-SDAG-NEXT: s_and_b32 s4, ttmp7, 0xffff | ||
; GFX9-SDAG-NEXT: global_store_dword v[0:1], v6, off | ||
; GFX9-SDAG-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v0, s4 | ||
; GFX9-SDAG-NEXT: s_lshr_b32 s4, ttmp7, 16 | ||
; GFX9-SDAG-NEXT: global_store_dword v[2:3], v0, off | ||
; GFX9-SDAG-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-SDAG-NEXT: v_mov_b32_e32 v0, s4 | ||
; GFX9-SDAG-NEXT: global_store_dword v[4:5], v0, off | ||
; GFX9-SDAG-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-SDAG-NEXT: s_setpc_b64 s[30:31] | ||
; | ||
; GFX9-GISEL-LABEL: workgroup_ids_device_func: | ||
; GFX9-GISEL: ; %bb.0: | ||
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
; GFX9-GISEL-NEXT: s_and_b32 s6, ttmp7, 0xffff | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v6, ttmp9 | ||
; GFX9-GISEL-NEXT: s_lshr_b32 s5, ttmp7, 16 | ||
; GFX9-GISEL-NEXT: global_store_dword v[0:1], v6, off | ||
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v0, s6 | ||
; GFX9-GISEL-NEXT: global_store_dword v[2:3], v0, off | ||
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-GISEL-NEXT: v_mov_b32_e32 v0, s5 | ||
; GFX9-GISEL-NEXT: global_store_dword v[4:5], v0, off | ||
; GFX9-GISEL-NEXT: s_waitcnt vmcnt(0) | ||
; GFX9-GISEL-NEXT: s_setpc_b64 s[30:31] | ||
%id.x = call i32 @llvm.amdgcn.workgroup.id.x() | ||
%id.y = call i32 @llvm.amdgcn.workgroup.id.y() | ||
%id.z = call i32 @llvm.amdgcn.workgroup.id.z() | ||
store volatile i32 %id.x, ptr addrspace(1) %outx | ||
store volatile i32 %id.y, ptr addrspace(1) %outy | ||
store volatile i32 %id.z, ptr addrspace(1) %outz | ||
ret void | ||
} | ||
|
||
declare i32 @llvm.amdgcn.workgroup.id.x() | ||
declare i32 @llvm.amdgcn.workgroup.id.y() | ||
declare i32 @llvm.amdgcn.workgroup.id.z() | ||
declare void @llvm.amdgcn.raw.ptr.buffer.store.v3i32(<3 x i32>, ptr addrspace(8), i32, i32, i32 immarg) | ||
|
||
attributes #0 = { nounwind "amdgpu-no-workgroup-id-y" "amdgpu-no-workgroup-id-z" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these really need to be tracked in ArgumentUsageInfo; they aren't arguments anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I started again from scratch: #79120