1 # RUN: llc -mtriple=amdgcn -mcpu=gfx803 -run-pass si-insert-waitcnts %s -o - | FileCheck -check-prefixes=CHECK,GFX89 %s
2 # RUN: llc -mtriple=amdgcn -mcpu=gfx900 -run-pass si-insert-waitcnts %s -o - | FileCheck -check-prefixes=CHECK,GFX89 %s
5 define amdgpu_kernel void @flat_zero_waitcnt(ptr addrspace(1) %global4,
6 ptr addrspace(1) %global16,
12 define amdgpu_kernel void @single_fallthrough_successor_no_end_block_wait() {
16 define amdgpu_kernel void @single_branch_successor_not_next_block() {
20 define amdgpu_kernel void @preexisting_waitcnt() {
24 define amdgpu_kernel void @bundle_no_waitcnt() {
28 define amdgpu_kernel void @preexisting_waitcnt_in_bundle() {
32 define amdgpu_kernel void @insert_in_bundle() {
36 define amdgpu_kernel void @exit_bundle() {
40 define amdgpu_kernel void @cross_bundle() {
44 define amdgpu_kernel void @subregs16bit() {
48 define amdgpu_kernel void @waitcnt_backedge() {
54 # CHECK-LABEL: name: flat_zero_waitcnt
57 # CHECK: FLAT_LOAD_DWORD
58 # CHECK: FLAT_LOAD_DWORDX4
59 # Global loads will return in order so we should:
61 # CHECK-NEXT: S_WAITCNT 3953
64 # CHECK: FLAT_LOAD_DWORD
66 # GFX89: S_WAITCNT 3952
67 # CHECK: FLAT_LOAD_DWORDX4
70 # CHECK: FLAT_LOAD_DWORD
72 # GFX89: S_WAITCNT 3952
73 # CHECK: FLAT_LOAD_DWORDX4
77 # GFX89: S_WAITCNT 3952
78 # CHECK: FLAT_LOAD_DWORD
79 # CHECK: FLAT_LOAD_DWORD
80 # s_waitcnt vmcnt(0) lgkmcnt(0)
81 # GFX89: S_WAITCNT 112
84 # GFX89-NOT: S_WAITCNT
85 # CHECK: FLAT_LOAD_DWORD
86 # s_waitcnt vmcnt(0) lgkmcnt(0)
87 # GFX89: S_WAITCNT 112
89 name: flat_zero_waitcnt
94 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %ir.global4)
95 $vgpr3_vgpr4_vgpr5_vgpr6 = FLAT_LOAD_DWORDX4 $vgpr7_vgpr8, 0, 0, implicit $exec, implicit $flat_scr :: (load (s128) from %ir.global16)
96 $vgpr0 = V_MOV_B32_e32 $vgpr1, implicit $exec
101 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
102 $vgpr3_vgpr4_vgpr5_vgpr6 = FLAT_LOAD_DWORDX4 $vgpr7_vgpr8, 0, 0, implicit $exec, implicit $flat_scr :: (load (s128) from %ir.global16)
103 $vgpr0 = V_MOV_B32_e32 $vgpr1, implicit $exec
108 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %ir.flat4)
109 $vgpr3_vgpr4_vgpr5_vgpr6 = FLAT_LOAD_DWORDX4 $vgpr7_vgpr8, 0, 0, implicit $exec, implicit $flat_scr :: (load (s128) from %ir.flat16)
110 $vgpr0 = V_MOV_B32_e32 $vgpr1, implicit $exec
115 $vgpr3 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %ir.flat4)
116 $vgpr4 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %ir.global4)
117 $vgpr0 = V_MOV_B32_e32 $vgpr3, implicit $exec
121 $vgpr5 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr :: (load (s32) from %ir.flat4)
122 $vgpr0 = V_MOV_B32_e32 $vgpr5, implicit $exec
126 # There is only a single fallthrough successor block, so there's no
127 # need to wait immediately.
129 # CHECK-LABEL: name: single_fallthrough_successor_no_end_block_wait
130 # CHECK: $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2
131 # CHECK-NOT: S_WAITCNT
134 # CHECK-NEXT: V_LSHLREV_B64_e64
135 # CHECK-NEXT: S_WAITCNT 112
136 # CHECK-NEXT: FLAT_STORE_DWORD
137 name: single_fallthrough_successor_no_end_block_wait
142 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
145 $vgpr3_vgpr4 = V_LSHLREV_B64_e64 4, $vgpr7_vgpr8, implicit $exec
146 FLAT_STORE_DWORD $vgpr3_vgpr4, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
150 # The block has a single predecessor with a single successor, but it
151 # is not the next block so it's non-obvious that the wait is not needed.
154 # CHECK-LABEL: name: single_branch_successor_not_next_block
157 # CHECK-NEXT: FLAT_STORE_DWORD
158 # CHECK-NEXT: S_ENDPGM 0
161 # CHECK-NEXT: V_LSHLREV_B64_e64
162 # CHECK-NEXT: S_WAITCNT 112
163 # CHECK-NEXT: FLAT_STORE_DWORD
164 name: single_branch_successor_not_next_block
169 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
173 FLAT_STORE_DWORD $vgpr8_vgpr9, $vgpr10, 0, 0, implicit $exec, implicit $flat_scr
177 $vgpr3_vgpr4 = V_LSHLREV_B64_e64 4, $vgpr7_vgpr8, implicit $exec
178 FLAT_STORE_DWORD $vgpr3_vgpr4, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
182 # CHECK-LABEL: name: preexisting_waitcnt{{$}}
183 # CHECK: FLAT_LOAD_DWORD
184 # CHECK-NEXT: S_WAITCNT 0
185 # CHECK-NOT: S_WAITCNT
186 name: preexisting_waitcnt
187 tracksRegLiveness: true
189 isEntryFunction: true
192 liveins: $vgpr1_vgpr2
193 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
195 FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
201 # CHECK-LABEL: name: bundle_no_waitcnt{{$}}
202 # CHECK: FLAT_LOAD_DWORD
207 # CHECK-NEXT: S_WAITCNT 112
208 name: bundle_no_waitcnt
209 tracksRegLiveness: true
211 isEntryFunction: true
214 liveins: $vgpr1_vgpr2
215 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
220 FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
226 # See the waitcnt inside the bundle and don't insert an extra
227 # CHECK-LABEL: name: preexisting_waitcnt_in_bundle{{$}}
228 # CHECK: FLAT_LOAD_DWORD
230 # CHECK-NOT: S_WAITCNT
231 name: preexisting_waitcnt_in_bundle
232 tracksRegLiveness: true
234 isEntryFunction: true
237 liveins: $vgpr1_vgpr2
238 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
243 FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
249 # Def and use inside bundle
250 # CHECK-LABEL: name: insert_in_bundle{{$}}
251 # CHECK: BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
252 # CHECK-NEXT: $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
253 # CHECK-NEXT: S_WAITCNT 112
254 # CHECK-NEXT: FLAT_STORE_DWORD $vgpr1_vgpr2, internal $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
257 name: insert_in_bundle
258 tracksRegLiveness: true
260 isEntryFunction: true
263 liveins: $vgpr1_vgpr2
264 BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
265 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
266 FLAT_STORE_DWORD $vgpr1_vgpr2, internal $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
272 # Def is last instruction in bundle, use is outside bundle
274 # CHECK-LABEL: name: exit_bundle{{$}}
275 # CHECK: BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
276 # CHECK-NEXT: $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
278 # CHECK-NEXT: S_WAITCNT 112
279 # CHECK-NEXT: FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
282 tracksRegLiveness: true
284 isEntryFunction: true
287 liveins: $vgpr1_vgpr2
288 BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
289 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
292 FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
298 # Def is in bundle, use is in another bundle
300 # CHECK-LABEL: name: cross_bundle{{$}}
301 # CHECK: BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
302 # CHECK-NEXT: $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
304 # CHECK-NEXT: BUNDLE implicit $vgpr0, implicit $vgpr1_vgpr2 {
305 # CHECK-NEXT: S_WAITCNT 112
306 # CHECK-NEXT: FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
310 tracksRegLiveness: true
312 isEntryFunction: true
315 liveins: $vgpr1_vgpr2
316 BUNDLE implicit-def $vgpr0, implicit $vgpr1_vgpr2 {
317 $vgpr0 = FLAT_LOAD_DWORD $vgpr1_vgpr2, 0, 0, implicit $exec, implicit $flat_scr
319 BUNDLE implicit $vgpr0, implicit $vgpr1_vgpr2 {
320 FLAT_STORE_DWORD $vgpr1_vgpr2, $vgpr0, 0, 0, implicit $exec, implicit $flat_scr
325 # CHECK-LABEL: name: subregs16bit
326 # CHECK: S_WAITCNT 112
327 # CHECK-NEXT: V_NOP_e32
331 isEntryFunction: true
334 liveins: $vgpr0_vgpr1, $vgpr2_vgpr3, $vgpr4
335 $vgpr0 = FLAT_LOAD_USHORT killed $vgpr0_vgpr1, 0, 0, implicit $exec, implicit $flat_scr
336 $vgpr1 = FLAT_LOAD_USHORT killed $vgpr2_vgpr3, 0, 0, implicit $exec, implicit $flat_scr
337 V_NOP_e32 implicit $exec, implicit $vgpr0_lo16, implicit $vgpr1_lo16
341 # Waitcnt required before the use of $sgpr10_sgpr11, as the S_LOAD also writes
342 # to $sgpr10_sgpr11, and can occur first in the program running order.
344 # CHECK-LABEL: name: waitcnt_backedge
346 # CHECK: $sgpr10_sgpr11 = S_CSELECT_B64
347 # CHECK: $sgpr10_sgpr11 = S_LOAD_DWORDX2_IMM
350 name: waitcnt_backedge
353 renamable $sgpr4_sgpr5_sgpr6_sgpr7 = S_LOAD_DWORDX4_IMM renamable $sgpr2_sgpr3, 32, 0 :: (load (s128) from `ptr addrspace(4) undef`, addrspace 4)
356 renamable $sgpr10_sgpr11 = S_CSELECT_B64 -1, 0, implicit killed $scc
357 renamable $vgpr1 = BUFFER_LOAD_DWORD_OFFEN killed renamable $vgpr5, renamable $sgpr4_sgpr5_sgpr6_sgpr7, 0, 0, 1, 0, implicit $exec :: (dereferenceable load (s32), align 1, addrspace 4)
358 renamable $sgpr10_sgpr11 = S_LOAD_DWORDX2_IMM killed renamable $sgpr0_sgpr1, 0, 0 :: (load (s64) from `ptr addrspace(4) undef`, align 4, addrspace 4)
359 S_CBRANCH_SCC0 %bb.9, implicit killed $scc
362 renamable $vgpr1 = V_CNDMASK_B32_e64 0, 0, 0, 1, killed $sgpr14_sgpr15, implicit $exec
363 S_CBRANCH_SCC0 %bb.14, implicit killed $scc