1 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
2 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=hawaii -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
3 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,LOOP %s
4 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,NOLOOP %s
5 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1010 -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,NOLOOP,GFX10 %s
7 ; Make sure the op is emitted bundled with a waitcnt with and without the retry loop, and the bundle is not removed by ExpandPostRAPseudos.
8 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -stop-after=postrapseudos -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=MIR %s
9 ; RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -stop-after=postrapseudos -o - -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefix=MIR %s
13 ; GCN-LABEL: {{^}}gws_barrier_offset0:
14 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
15 ; NOLOOP-DAG: s_mov_b32 m0, 0{{$}}
16 ; NOLOOP: v_mov_b32_e32 v0, [[BAR_NUM]]
17 ; NOLOOP: ds_gws_barrier v0 gds{{$}}
19 ; LOOP: s_mov_b32 m0, 0{{$}}
20 ; LOOP: [[LOOP:BB[0-9]+_[0-9]+]]:
21 ; LOOP-NEXT: s_setreg_imm32_b32 hwreg(HW_REG_TRAPSTS, 8, 1), 0
22 ; LOOP-NEXT: ds_gws_barrier v0 gds
23 ; LOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
24 ; LOOP-NEXT: s_getreg_b32 [[GETREG:s[0-9]+]], hwreg(HW_REG_TRAPSTS, 8, 1)
25 ; LOOP-NEXT: s_cmp_lg_u32 [[GETREG]], 0
26 ; LOOP-NEXT: s_cbranch_scc1 [[LOOP]]
28 ; MIR-LABEL: name: gws_barrier_offset0{{$}}
29 ; MIR: BUNDLE implicit{{( killed)?( renamable)?}} $vgpr0, implicit $m0, implicit $exec {
30 ; MIR-NEXT: DS_GWS_BARRIER renamable $vgpr0, 0, -1, implicit $m0, implicit $exec :: (load 4 from custom GWSResource)
31 ; MIR-NEXT: S_WAITCNT 0
33 define amdgpu_kernel void @gws_barrier_offset0(i32 %val) #0 {
34 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 0)
38 ; MIR-LABEL: name: gws_barrier_offset63{{$}}
41 ; GCN-LABEL: {{^}}gws_barrier_offset63:
42 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
43 ; NOLOOP-DAG: s_mov_b32 m0, 0{{$}}
44 ; NOLOOP-DAG: v_mov_b32_e32 v0, [[BAR_NUM]]
45 ; NOLOOP: ds_gws_barrier v0 offset:63 gds{{$}}
46 define amdgpu_kernel void @gws_barrier_offset63(i32 %val) #0 {
47 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 63)
51 ; FIXME: Should be able to shift directly into m0
52 ; GCN-LABEL: {{^}}gws_barrier_sgpr_offset:
53 ; NOLOOP-DAG: s_load_dwordx2 s{{\[}}[[BAR_NUM:[0-9]+]]:[[OFFSET:[0-9]+]]{{\]}}
54 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], s[[OFFSET]], 16
55 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
56 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], s[[BAR_NUM]]
57 ; NOLOOP: ds_gws_barrier [[GWS_VAL]] gds{{$}}
58 define amdgpu_kernel void @gws_barrier_sgpr_offset(i32 %val, i32 %offset) #0 {
59 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 %offset)
63 ; Variable offset in SGPR with constant add
64 ; GCN-LABEL: {{^}}gws_barrier_sgpr_offset_add1:
65 ; NOLOOP-DAG: s_load_dwordx2 s{{\[}}[[BAR_NUM:[0-9]+]]:[[OFFSET:[0-9]+]]{{\]}}
66 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], s[[OFFSET]], 16
67 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
68 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], s[[BAR_NUM]]
69 ; NOLOOP: ds_gws_barrier [[GWS_VAL]] offset:1 gds{{$}}
70 define amdgpu_kernel void @gws_barrier_sgpr_offset_add1(i32 %val, i32 %offset.base) #0 {
71 %offset = add i32 %offset.base, 1
72 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 %offset)
76 ; GCN-LABEL: {{^}}gws_barrier_vgpr_offset:
77 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
78 ; NOLOOP-DAG: v_readfirstlane_b32 [[READLANE:s[0-9]+]], v0
79 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], [[READLANE]], 16
80 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
81 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], [[BAR_NUM]]
82 ; NOLOOP: ds_gws_barrier [[GWS_VAL]] gds{{$}}
83 define amdgpu_kernel void @gws_barrier_vgpr_offset(i32 %val) #0 {
84 %vgpr.offset = call i32 @llvm.amdgcn.workitem.id.x()
85 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 %vgpr.offset)
89 ; Variable offset in VGPR with constant add
90 ; GCN-LABEL: {{^}}gws_barrier_vgpr_offset_add:
91 ; NOLOOP-DAG: s_load_dword [[BAR_NUM:s[0-9]+]]
92 ; NOLOOP-DAG: v_readfirstlane_b32 [[READLANE:s[0-9]+]], v0
93 ; NOLOOP-DAG: s_lshl_b32 [[SHL:s[0-9]+]], [[READLANE]], 16
94 ; NOLOOP-DAG: s_mov_b32 m0, [[SHL]]{{$}}
95 ; NOLOOP-DAG: v_mov_b32_e32 [[GWS_VAL:v[0-9]+]], [[BAR_NUM]]
96 ; NOLOOP: ds_gws_barrier [[GWS_VAL]] offset:3 gds{{$}}
97 define amdgpu_kernel void @gws_barrier_vgpr_offset_add(i32 %val) #0 {
98 %vgpr.offset.base = call i32 @llvm.amdgcn.workitem.id.x()
99 %vgpr.offset = add i32 %vgpr.offset.base, 3
100 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 %vgpr.offset)
104 @lds = internal unnamed_addr addrspace(3) global i32 undef
106 ; Check if m0 initialization is shared
107 ; GCN-LABEL: {{^}}gws_barrier_save_m0_barrier_constant_offset:
108 ; NOLOOP: s_mov_b32 m0, 0
109 ; NOLOOP: ds_gws_barrier v{{[0-9]+}} offset:10 gds
111 ; LOOP: s_mov_b32 m0, -1
113 ; LOOP: s_mov_b32 m0, 0
114 ; LOOP: s_setreg_imm32_b32
115 ; LOOP: ds_gws_barrier v{{[0-9]+}} offset:10 gds
116 ; LOOP: s_cbranch_scc1
118 ; LOOP: s_mov_b32 m0, -1
120 define amdgpu_kernel void @gws_barrier_save_m0_barrier_constant_offset(i32 %val) #0 {
121 store i32 1, i32 addrspace(3)* @lds
122 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 10)
123 store i32 2, i32 addrspace(3)* @lds
127 ; Make sure this increments lgkmcnt
128 ; GCN-LABEL: {{^}}gws_barrier_lgkmcnt:
129 ; NOLOOP: s_mov_b32 m0, 0{{$}}
130 ; NOLOOP: ds_gws_barrier v0 gds{{$}}
131 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
132 ; NOLOOP-NEXT: s_setpc_b64
133 define void @gws_barrier_lgkmcnt(i32 %val) {
134 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 0)
138 ; Does not imply memory fence on its own
139 ; GCN-LABEL: {{^}}gws_barrier_wait_before:
141 ; NOLOOP-NOT: s_waitcnt{{$}}
142 define amdgpu_kernel void @gws_barrier_wait_before(i32 %val, i32 addrspace(1)* %ptr) #0 {
143 store i32 0, i32 addrspace(1)* %ptr
144 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
148 ; GCN-LABEL: {{^}}gws_barrier_wait_after:
149 ; NOLOOP: s_mov_b32 m0, 0{{$}}
150 ; NOLOOP: ds_gws_barrier v{{[0-9]+}} offset:7 gds
151 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
152 ; NOLOOP-NEXT: load_dword
153 define amdgpu_kernel void @gws_barrier_wait_after(i32 %val, i32 addrspace(1)* %ptr) #0 {
154 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
155 %load = load volatile i32, i32 addrspace(1)* %ptr
159 ; Does not imply memory fence on its own
160 ; GCN-LABEL: {{^}}gws_barrier_fence_before:
161 ; NOLOOP: s_mov_b32 m0, 0{{$}}
162 ; NOLOOP: store_dword
163 ; NOLOOP: s_waitcnt vmcnt(0) lgkmcnt(0)
164 ; NOLOOP: ds_gws_barrier v{{[0-9]+}} offset:7 gds
165 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
166 define amdgpu_kernel void @gws_barrier_fence_before(i32 %val, i32 addrspace(1)* %ptr) #0 {
167 store i32 0, i32 addrspace(1)* %ptr
169 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
173 ; FIXME: Extra waitcnt
174 ; GCN-LABEL: {{^}}gws_barrier_fence_after:
175 ; NOLOOP: s_mov_b32 m0, 0{{$}}
176 ; NOLOOP: ds_gws_barrier v{{[0-9]+}} offset:7 gds
177 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
178 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
179 ; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
180 ; NOLOOP-NEXT: load_dword
181 define amdgpu_kernel void @gws_barrier_fence_after(i32 %val, i32 addrspace(1)* %ptr) #0 {
182 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
184 %load = load volatile i32, i32 addrspace(1)* %ptr
188 ; FIXME: Should a wait be inserted here, or is an explicit fence needed?
189 ; GCN-LABEL: {{^}}gws_init_barrier:
190 ; NOLOOP: s_mov_b32 m0, 0
191 ; NOLOOP: ds_gws_init v0 offset:7 gds
192 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
193 ; NOLOOP-NEXT: ds_gws_barrier v0 offset:7 gds
194 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
195 define amdgpu_kernel void @gws_init_barrier(i32 %val) #0 {
196 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 7)
197 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
201 ; FIXME: Why vmcnt, not expcnt?
202 ; GCN-LABEL: {{^}}gws_init_fence_barrier:
203 ; NOLOOP: s_mov_b32 m0, 0
204 ; NOLOOP: ds_gws_init v0 offset:7 gds
205 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
206 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) lgkmcnt(0)
207 ; GFX10-NEXT: s_waitcnt_vscnt null, 0x0
208 ; NOLOOP-NEXT: ds_gws_barrier v0 offset:7 gds
209 ; NOLOOP-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
210 define amdgpu_kernel void @gws_init_fence_barrier(i32 %val) #0 {
211 call void @llvm.amdgcn.ds.gws.init(i32 %val, i32 7)
213 call void @llvm.amdgcn.ds.gws.barrier(i32 %val, i32 7)
217 declare void @llvm.amdgcn.ds.gws.barrier(i32, i32) #1
218 declare void @llvm.amdgcn.ds.gws.init(i32, i32) #2
219 declare i32 @llvm.amdgcn.workitem.id.x() #3
221 attributes #0 = { nounwind }
222 attributes #1 = { convergent inaccessiblememonly nounwind }
223 attributes #2 = { convergent inaccessiblememonly nounwind writeonly }
224 attributes #3 = { nounwind readnone speculatable }