1 ; RUN: opt -mtriple=amdgcn-- -passes=amdgpu-attributor -o %t.bc %s
2 ; RUN: llc -mtriple=amdgcn -mcpu=hawaii < %t.bc | FileCheck --check-prefixes=ALL,MESA,UNPACKED %s
3 ; RUN: llc -mtriple=amdgcn -mcpu=tonga -mattr=-flat-for-global < %t.bc | FileCheck --check-prefixes=ALL,MESA,UNPACKED %s
4 ; RUN: llc -mtriple=amdgcn-unknown-mesa3d -mcpu=hawaii < %t.bc | FileCheck -check-prefixes=ALL,MESA3D,UNPACKED %s
5 ; RUN: llc -mtriple=amdgcn-unknown-mesa3d -mcpu=tonga -mattr=-flat-for-global < %t.bc | FileCheck -check-prefixes=ALL,MESA3D,UNPACKED %s
6 ; RUN: llc -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx90a < %t.bc | FileCheck -check-prefixes=ALL,PACKED-TID %s
7 ; RUN: llc -mtriple=amdgcn-unknown-amdhsa -mcpu=gfx1100 -amdgpu-enable-vopd=0 < %t.bc | FileCheck -check-prefixes=ALL,PACKED-TID %s
9 declare i32 @llvm.amdgcn.workitem.id.x() #0
10 declare i32 @llvm.amdgcn.workitem.id.y() #0
11 declare i32 @llvm.amdgcn.workitem.id.z() #0
13 ; MESA: .section .AMDGPU.config
15 ; MESA-NEXT: .long 132{{$}}
17 ; ALL-LABEL: {{^}}test_workitem_id_x:
18 ; MESA3D: enable_vgpr_workitem_id = 0
21 ; ALL: {{buffer|flat|global}}_store_{{dword|b32}} {{.*}}v0
23 ; PACKED-TID: .amdhsa_system_vgpr_workitem_id 0
24 define amdgpu_kernel void @test_workitem_id_x(ptr addrspace(1) %out) #1 {
25 %id = call i32 @llvm.amdgcn.workitem.id.x()
26 store i32 %id, ptr addrspace(1) %out
30 ; MESA: .section .AMDGPU.config
32 ; MESA-NEXT: .long 2180{{$}}
34 ; ALL-LABEL: {{^}}test_workitem_id_y:
35 ; MESA3D: enable_vgpr_workitem_id = 1
37 ; MESA3D: {{buffer|flat}}_store_dword {{.*}}v1
39 ; PACKED-TID: v_bfe_u32 [[ID:v[0-9]+]], v0, 10, 10
40 ; PACKED-TID: {{buffer|flat|global}}_store_{{dword|b32}} {{.*}}[[ID]]
41 ; PACKED-TID: .amdhsa_system_vgpr_workitem_id 1
42 define amdgpu_kernel void @test_workitem_id_y(ptr addrspace(1) %out) #1 {
43 %id = call i32 @llvm.amdgcn.workitem.id.y()
44 store i32 %id, ptr addrspace(1) %out
48 ; MESA: .section .AMDGPU.config
50 ; MESA-NEXT: .long 4228{{$}}
52 ; ALL-LABEL: {{^}}test_workitem_id_z:
53 ; MESA3D: enable_vgpr_workitem_id = 2
55 ; MESA3D: {{buffer|flat}}_store_dword {{.*}}v2
57 ; PACKED-TID: v_bfe_u32 [[ID:v[0-9]+]], v0, 20, 10
58 ; PACKED-TID: {{buffer|flat|global}}_store_{{dword|b32}} {{.*}}[[ID]]
59 ; PACKED-TID: .amdhsa_system_vgpr_workitem_id 2
60 define amdgpu_kernel void @test_workitem_id_z(ptr addrspace(1) %out) #1 {
61 %id = call i32 @llvm.amdgcn.workitem.id.z()
62 store i32 %id, ptr addrspace(1) %out
66 ; FIXME: Packed tid should avoid the and
67 ; ALL-LABEL: {{^}}test_reqd_workgroup_size_x_only:
68 ; MESA3D: enable_vgpr_workitem_id = 0
70 ; ALL-DAG: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
71 ; UNPACKED-DAG: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, v0
73 ; PACKED: v_and_b32_e32 [[MASKED:v[0-9]+]], 0x3ff, v0
74 ; PACKED: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, [[MASKED]]
76 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
77 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
78 define amdgpu_kernel void @test_reqd_workgroup_size_x_only(ptr %out) !reqd_work_group_size !0 {
79 %id.x = call i32 @llvm.amdgcn.workitem.id.x()
80 %id.y = call i32 @llvm.amdgcn.workitem.id.y()
81 %id.z = call i32 @llvm.amdgcn.workitem.id.z()
82 store volatile i32 %id.x, ptr %out
83 store volatile i32 %id.y, ptr %out
84 store volatile i32 %id.z, ptr %out
88 ; ALL-LABEL: {{^}}test_reqd_workgroup_size_y_only:
89 ; MESA3D: enable_vgpr_workitem_id = 1
91 ; ALL: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
92 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
94 ; UNPACKED: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, v1
96 ; PACKED: v_bfe_u32 [[MASKED:v[0-9]+]], v0, 10, 10
97 ; PACKED: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, [[MASKED]]
99 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
100 define amdgpu_kernel void @test_reqd_workgroup_size_y_only(ptr %out) !reqd_work_group_size !1 {
101 %id.x = call i32 @llvm.amdgcn.workitem.id.x()
102 %id.y = call i32 @llvm.amdgcn.workitem.id.y()
103 %id.z = call i32 @llvm.amdgcn.workitem.id.z()
104 store volatile i32 %id.x, ptr %out
105 store volatile i32 %id.y, ptr %out
106 store volatile i32 %id.z, ptr %out
110 ; ALL-LABEL: {{^}}test_reqd_workgroup_size_z_only:
111 ; MESA3D: enable_vgpr_workitem_id = 2
113 ; ALL: v_mov_b32_e32 [[ZERO:v[0-9]+]], 0{{$}}
114 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
115 ; ALL: flat_store_{{dword|b32}} v{{\[[0-9]+:[0-9]+\]}}, [[ZERO]]
117 ; UNPACKED: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, v2
119 ; PACKED: v_bfe_u32 [[MASKED:v[0-9]+]], v0, 10, 20
120 ; PACKED: flat_store_dword v{{\[[0-9]+:[0-9]+\]}}, [[MASKED]]
121 define amdgpu_kernel void @test_reqd_workgroup_size_z_only(ptr %out) !reqd_work_group_size !2 {
122 %id.x = call i32 @llvm.amdgcn.workitem.id.x()
123 %id.y = call i32 @llvm.amdgcn.workitem.id.y()
124 %id.z = call i32 @llvm.amdgcn.workitem.id.z()
125 store volatile i32 %id.x, ptr %out
126 store volatile i32 %id.y, ptr %out
127 store volatile i32 %id.z, ptr %out
131 attributes #0 = { nounwind readnone }
132 attributes #1 = { nounwind }
134 !llvm.module.flags = !{!3}
136 !0 = !{i32 64, i32 1, i32 1}
137 !1 = !{i32 1, i32 64, i32 1}
138 !2 = !{i32 1, i32 1, i32 64}
139 !3 = !{i32 1, !"amdhsa_code_object_version", i32 400}