blob: 578f94241c6a0cc895c6cf3b58cddcb461698f13 [file] [log] [blame]
Matt Arsenault6bc43d82016-10-06 16:20:41 +00001; RUN: llc -march=amdgcn -verify-machineinstrs -amdgpu-s-branch-bits=4 < %s | FileCheck -check-prefix=GCN %s
Rafael Espindola2c166852017-06-24 04:31:45 +00002
3
4; FIXME: We should use llvm-mc for this, but we can't even parse our own output.
5; See PR33579.
6; RUN: llc -march=amdgcn -verify-machineinstrs -amdgpu-s-branch-bits=4 -o %t.o -filetype=obj
7; RUN: llvm-readobj -r %t.o | FileCheck --check-prefix=OBJ %s
8
9; OBJ: Relocations [
10; OBJ-NEXT: ]
11
Matt Arsenault6bc43d82016-10-06 16:20:41 +000012; Restrict maximum branch to between +7 and -8 dwords
13
14; Used to emit an always 4 byte instruction. Inline asm always assumes
15; each instruction is the maximum size.
16declare void @llvm.amdgcn.s.sleep(i32) #0
17
18declare i32 @llvm.amdgcn.workitem.id.x() #1
19
20
21; GCN-LABEL: {{^}}uniform_conditional_max_short_forward_branch:
22; GCN: s_load_dword [[CND:s[0-9]+]]
23; GCN: s_cmp_eq_u32 [[CND]], 0
24; GCN-NEXT: s_cbranch_scc1 [[BB3:BB[0-9]+_[0-9]+]]
25
26
27; GCN-NEXT: ; BB#1: ; %bb2
28; GCN-NEXT: ;;#ASMSTART
29; GCN-NEXT: v_nop_e64
30; GCN-NEXT: v_nop_e64
31; GCN-NEXT: v_nop_e64
32; GCN-NEXT: ;;#ASMEND
33; GCN-NEXT: s_sleep 0
34
35; GCN-NEXT: [[BB3]]: ; %bb3
36; GCN: v_mov_b32_e32 [[V_CND:v[0-9]+]], [[CND]]
37; GCN: buffer_store_dword [[V_CND]]
38; GCN: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000039define amdgpu_kernel void @uniform_conditional_max_short_forward_branch(i32 addrspace(1)* %arg, i32 %cnd) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +000040bb:
41 %cmp = icmp eq i32 %cnd, 0
42 br i1 %cmp, label %bb3, label %bb2 ; +8 dword branch
43
44bb2:
45; 24 bytes
46 call void asm sideeffect
47 "v_nop_e64
48 v_nop_e64
49 v_nop_e64", ""() #0
50 call void @llvm.amdgcn.s.sleep(i32 0)
51 br label %bb3
52
53bb3:
54 store volatile i32 %cnd, i32 addrspace(1)* %arg
55 ret void
56}
57
58; GCN-LABEL: {{^}}uniform_conditional_min_long_forward_branch:
59; GCN: s_load_dword [[CND:s[0-9]+]]
60; GCN: s_cmp_eq_u32 [[CND]], 0
61; GCN-NEXT: s_cbranch_scc0 [[LONGBB:BB[0-9]+_[0-9]+]]
62
63; GCN-NEXT: [[LONG_JUMP:BB[0-9]+_[0-9]+]]: ; %bb0
64; GCN-NEXT: s_getpc_b64 vcc
65; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[ENDBB:BB[0-9]+_[0-9]+]]-([[LONG_JUMP]]+4)
66; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0
67; GCN-NEXT: s_setpc_b64 vcc
68
69; GCN-NEXT: [[LONGBB]]:
70; GCN-NEXT: ;;#ASMSTART
71; GCN: v_nop_e64
72; GCN: v_nop_e64
73; GCN: v_nop_e64
74; GCN: v_nop_e64
75; GCN-NEXT: ;;#ASMEND
76
77; GCN-NEXT: [[ENDBB]]:
78; GCN: v_mov_b32_e32 [[V_CND:v[0-9]+]], [[CND]]
79; GCN: buffer_store_dword [[V_CND]]
80; GCN: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000081define amdgpu_kernel void @uniform_conditional_min_long_forward_branch(i32 addrspace(1)* %arg, i32 %cnd) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +000082bb0:
83 %cmp = icmp eq i32 %cnd, 0
84 br i1 %cmp, label %bb3, label %bb2 ; +9 dword branch
85
86bb2:
87; 32 bytes
88 call void asm sideeffect
89 "v_nop_e64
90 v_nop_e64
91 v_nop_e64
92 v_nop_e64", ""() #0
93 br label %bb3
94
95bb3:
96 store volatile i32 %cnd, i32 addrspace(1)* %arg
97 ret void
98}
99
100; GCN-LABEL: {{^}}uniform_conditional_min_long_forward_vcnd_branch:
101; GCN: s_load_dword [[CND:s[0-9]+]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000102; GCN-DAG: v_mov_b32_e32 [[V_CND:v[0-9]+]], [[CND]]
Stanislav Mekhanoshin6fc8a1c2016-11-11 00:22:34 +0000103; GCN-DAG: v_cmp_eq_f32_e64 vcc, [[CND]], 0
Matt Arsenaultf530e8b2016-11-07 19:09:33 +0000104; GCN: s_cbranch_vccz [[LONGBB:BB[0-9]+_[0-9]+]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000105
106; GCN-NEXT: [[LONG_JUMP:BB[0-9]+_[0-9]+]]: ; %bb0
107; GCN-NEXT: s_getpc_b64 vcc
108; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[ENDBB:BB[0-9]+_[0-9]+]]-([[LONG_JUMP]]+4)
109; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0
110; GCN-NEXT: s_setpc_b64 vcc
111
112; GCN-NEXT: [[LONGBB]]:
113; GCN: v_nop_e64
114; GCN: v_nop_e64
115; GCN: v_nop_e64
116; GCN: v_nop_e64
117
118; GCN: [[ENDBB]]:
119; GCN: buffer_store_dword [[V_CND]]
120; GCN: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000121define amdgpu_kernel void @uniform_conditional_min_long_forward_vcnd_branch(float addrspace(1)* %arg, float %cnd) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000122bb0:
123 %cmp = fcmp oeq float %cnd, 0.0
124 br i1 %cmp, label %bb3, label %bb2 ; + 8 dword branch
125
126bb2:
127 call void asm sideeffect " ; 32 bytes
128 v_nop_e64
129 v_nop_e64
130 v_nop_e64
131 v_nop_e64", ""() #0
132 br label %bb3
133
134bb3:
135 store volatile float %cnd, float addrspace(1)* %arg
136 ret void
137}
138
139; GCN-LABEL: {{^}}min_long_forward_vbranch:
140
141; GCN: buffer_load_dword
142; GCN: v_cmp_ne_u32_e32 vcc, 0, v{{[0-9]+}}
143; GCN: s_and_saveexec_b64 [[SAVE:s\[[0-9]+:[0-9]+\]]], vcc
144; GCN: s_xor_b64 [[SAVE]], exec, [[SAVE]]
145
146; GCN: v_nop_e64
147; GCN: v_nop_e64
148; GCN: v_nop_e64
149; GCN: v_nop_e64
150
151; GCN: s_or_b64 exec, exec, [[SAVE]]
152; GCN: buffer_store_dword
153; GCN: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000154define amdgpu_kernel void @min_long_forward_vbranch(i32 addrspace(1)* %arg) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000155bb:
156 %tid = call i32 @llvm.amdgcn.workitem.id.x()
157 %tid.ext = zext i32 %tid to i64
158 %gep = getelementptr inbounds i32, i32 addrspace(1)* %arg, i64 %tid.ext
159 %load = load volatile i32, i32 addrspace(1)* %gep
160 %cmp = icmp eq i32 %load, 0
161 br i1 %cmp, label %bb3, label %bb2 ; + 8 dword branch
162
163bb2:
164 call void asm sideeffect " ; 32 bytes
165 v_nop_e64
166 v_nop_e64
167 v_nop_e64
168 v_nop_e64", ""() #0
169 br label %bb3
170
171bb3:
172 store volatile i32 %load, i32 addrspace(1)* %gep
173 ret void
174}
175
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000176; GCN-LABEL: {{^}}long_backward_sbranch:
Tom Stellard0bc68812016-11-29 00:46:46 +0000177; GCN: s_mov_b32 [[LOOPIDX:s[0-9]+]], 0{{$}}
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000178
179; GCN: [[LOOPBB:BB[0-9]+_[0-9]+]]: ; %bb2
180; GCN-NEXT: ; =>This Inner Loop Header: Depth=1
Tom Stellard0bc68812016-11-29 00:46:46 +0000181; GCN-NEXT: s_add_i32 [[INC:s[0-9]+]], [[LOOPIDX]], 1
182; GCN-NEXT: s_cmp_lt_i32 [[INC]], 10
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000183
184; GCN-NEXT: ;;#ASMSTART
185; GCN-NEXT: v_nop_e64
186; GCN-NEXT: v_nop_e64
187; GCN-NEXT: v_nop_e64
188; GCN-NEXT: ;;#ASMEND
189
Tom Stellard0bc68812016-11-29 00:46:46 +0000190; GCN-NEXT: s_cbranch_scc0 [[ENDBB:BB[0-9]+_[0-9]+]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000191
192; GCN-NEXT: [[LONG_JUMP:BB[0-9]+_[0-9]+]]: ; %bb2
193; GCN-NEXT: ; in Loop: Header=[[LOOPBB]] Depth=1
194; GCN-NEXT: s_getpc_b64 vcc
195; GCN-NEXT: s_sub_u32 vcc_lo, vcc_lo, ([[LONG_JUMP]]+4)-[[LOOPBB]]
196; GCN-NEXT: s_subb_u32 vcc_hi, vcc_hi, 0
197; GCN-NEXT: s_setpc_b64 vcc
198
199; GCN-NEXT: [[ENDBB]]:
200; GCN-NEXT: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000201define amdgpu_kernel void @long_backward_sbranch(i32 addrspace(1)* %arg) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000202bb:
203 br label %bb2
204
205bb2:
206 %loop.idx = phi i32 [ 0, %bb ], [ %inc, %bb2 ]
207 ; 24 bytes
208 call void asm sideeffect
209 "v_nop_e64
210 v_nop_e64
211 v_nop_e64", ""() #0
212 %inc = add nsw i32 %loop.idx, 1 ; add cost 4
213 %cmp = icmp slt i32 %inc, 10 ; condition cost = 8
214 br i1 %cmp, label %bb2, label %bb3 ; -
215
216bb3:
217 ret void
218}
219
220; Requires expansion of unconditional branch from %bb2 to %bb4 (and
221; expansion of conditional branch from %bb to %bb3.
222
223; GCN-LABEL: {{^}}uniform_unconditional_min_long_forward_branch:
224; GCN: s_cmp_eq_u32
225; GCN-NEXT: s_cbranch_scc0 [[BB2:BB[0-9]+_[0-9]+]]
226
227; GCN-NEXT: [[LONG_JUMP0:BB[0-9]+_[0-9]+]]: ; %bb0
228; GCN-NEXT: s_getpc_b64 vcc
229; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[BB3:BB[0-9]_[0-9]+]]-([[LONG_JUMP0]]+4)
230; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0{{$}}
231; GCN-NEXT: s_setpc_b64 vcc
232
233; GCN-NEXT: [[BB2]]: ; %bb2
234; GCN: v_mov_b32_e32 [[BB2_K:v[0-9]+]], 17
235; GCN: buffer_store_dword [[BB2_K]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000236
237; GCN-NEXT: [[LONG_JUMP1:BB[0-9]+_[0-9]+]]: ; %bb2
238; GCN-NEXT: s_getpc_b64 vcc
239; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[BB4:BB[0-9]_[0-9]+]]-([[LONG_JUMP1]]+4)
240; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0{{$}}
241; GCN-NEXT: s_setpc_b64 vcc
242
243; GCN: [[BB3]]: ; %bb3
244; GCN: v_nop_e64
245; GCN: v_nop_e64
246; GCN: v_nop_e64
247; GCN: v_nop_e64
248; GCN: ;;#ASMEND
249
250; GCN-NEXT: [[BB4]]: ; %bb4
251; GCN: v_mov_b32_e32 [[BB4_K:v[0-9]+]], 63
252; GCN: buffer_store_dword [[BB4_K]]
253; GCN-NEXT: s_endpgm
254; GCN-NEXT: .Lfunc_end{{[0-9]+}}:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000255define amdgpu_kernel void @uniform_unconditional_min_long_forward_branch(i32 addrspace(1)* %arg, i32 %arg1) {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000256bb0:
257 %tmp = icmp ne i32 %arg1, 0
258 br i1 %tmp, label %bb2, label %bb3
259
260bb2:
261 store volatile i32 17, i32 addrspace(1)* undef
262 br label %bb4
263
264bb3:
265 ; 32 byte asm
266 call void asm sideeffect
267 "v_nop_e64
268 v_nop_e64
269 v_nop_e64
270 v_nop_e64", ""() #0
271 br label %bb4
272
273bb4:
274 store volatile i32 63, i32 addrspace(1)* %arg
275 ret void
276}
277
278; GCN-LABEL: {{^}}uniform_unconditional_min_long_backward_branch:
279; GCN-NEXT: ; BB#0: ; %entry
280
281; GCN-NEXT: [[LOOP:BB[0-9]_[0-9]+]]: ; %loop
282; GCN-NEXT: ; =>This Inner Loop Header: Depth=1
283; GCN-NEXT: ;;#ASMSTART
284; GCN-NEXT: v_nop_e64
285; GCN-NEXT: v_nop_e64
286; GCN-NEXT: v_nop_e64
287; GCN-NEXT: v_nop_e64
288; GCN-NEXT: ;;#ASMEND
289
290; GCN-NEXT: [[LONGBB:BB[0-9]+_[0-9]+]]: ; %loop
291; GCN-NEXT: ; in Loop: Header=[[LOOP]] Depth=1
292; GCN-NEXT: s_getpc_b64 vcc
293; GCN-NEXT: s_sub_u32 vcc_lo, vcc_lo, ([[LONGBB]]+4)-[[LOOP]]
294; GCN-NEXT: s_subb_u32 vcc_hi, vcc_hi, 0{{$}}
295; GCN-NEXT: s_setpc_b64 vcc
296; GCN-NEXT .Lfunc_end{{[0-9]+}}:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000297define amdgpu_kernel void @uniform_unconditional_min_long_backward_branch(i32 addrspace(1)* %arg, i32 %arg1) {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000298entry:
299 br label %loop
300
301loop:
302 ; 32 byte asm
303 call void asm sideeffect
304 "v_nop_e64
305 v_nop_e64
306 v_nop_e64
307 v_nop_e64", ""() #0
308 br label %loop
309}
310
311; Expansion of branch from %bb1 to %bb3 introduces need to expand
312; branch from %bb0 to %bb2
313
314; GCN-LABEL: {{^}}expand_requires_expand:
315; GCN-NEXT: ; BB#0: ; %bb0
316; GCN: s_load_dword
317; GCN: s_cmp_lt_i32 s{{[0-9]+}}, 0{{$}}
318; GCN-NEXT: s_cbranch_scc0 [[BB1:BB[0-9]+_[0-9]+]]
319
320; GCN-NEXT: [[LONGBB0:BB[0-9]+_[0-9]+]]: ; %bb0
321; GCN-NEXT: s_getpc_b64 vcc
322; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[BB2:BB[0-9]_[0-9]+]]-([[LONGBB0]]+4)
323; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0{{$}}
324; GCN-NEXT: s_setpc_b64 vcc
325
326; GCN-NEXT: [[BB1]]: ; %bb1
327; GCN-NEXT: s_load_dword
328; GCN-NEXT: s_waitcnt lgkmcnt(0)
329; GCN-NEXT: s_cmp_eq_u32 s{{[0-9]+}}, 3{{$}}
330; GCN-NEXT: s_cbranch_scc0 [[BB2:BB[0-9]_[0-9]+]]
331
332; GCN-NEXT: [[LONGBB1:BB[0-9]+_[0-9]+]]: ; %bb1
333; GCN-NEXT: s_getpc_b64 vcc
334; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[BB3:BB[0-9]+_[0-9]+]]-([[LONGBB1]]+4)
335; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0{{$}}
336; GCN-NEXT: s_setpc_b64 vcc
337
338; GCN-NEXT: [[BB2]]: ; %bb2
339; GCN-NEXT: ;;#ASMSTART
340; GCN-NEXT: v_nop_e64
341; GCN-NEXT: v_nop_e64
342; GCN-NEXT: v_nop_e64
343; GCN-NEXT: v_nop_e64
344; GCN-NEXT: ;;#ASMEND
345
346; GCN-NEXT: [[BB3]]: ; %bb3
Kyle Buttb15c0662017-01-31 23:48:32 +0000347; GCN-NEXT: ;;#ASMSTART
348; GCN-NEXT: v_nop_e64
349; GCN-NEXT: ;;#ASMEND
350; GCN-NEXT: ;;#ASMSTART
351; GCN-NEXT: v_nop_e64
352; GCN-NEXT: ;;#ASMEND
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000353; GCN-NEXT: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000354define amdgpu_kernel void @expand_requires_expand(i32 %cond0) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000355bb0:
356 %tmp = tail call i32 @llvm.amdgcn.workitem.id.x() #0
357 %cmp0 = icmp slt i32 %cond0, 0
358 br i1 %cmp0, label %bb2, label %bb1
359
360bb1:
361 %val = load volatile i32, i32 addrspace(2)* undef
362 %cmp1 = icmp eq i32 %val, 3
363 br i1 %cmp1, label %bb3, label %bb2
364
365bb2:
366 call void asm sideeffect
367 "v_nop_e64
368 v_nop_e64
369 v_nop_e64
370 v_nop_e64", ""() #0
371 br label %bb3
372
373bb3:
Kyle Buttb15c0662017-01-31 23:48:32 +0000374; These NOPs prevent tail-duplication-based outlining
375; from firing, which defeats the need to expand the branches and this test.
376 call void asm sideeffect
377 "v_nop_e64", ""() #0
378 call void asm sideeffect
379 "v_nop_e64", ""() #0
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000380 ret void
381}
382
383; Requires expanding of required skip branch.
384
385; GCN-LABEL: {{^}}uniform_inside_divergent:
386; GCN: v_cmp_gt_u32_e32 vcc, 16, v{{[0-9]+}}
387; GCN-NEXT: s_and_saveexec_b64 [[MASK:s\[[0-9]+:[0-9]+\]]], vcc
388; GCN-NEXT: s_xor_b64 [[MASK1:s\[[0-9]+:[0-9]+\]]], exec, [[MASK]]
389; GCN-NEXT: ; mask branch [[ENDIF:BB[0-9]+_[0-9]+]]
390; GCN-NEXT: s_cbranch_execnz [[IF:BB[0-9]+_[0-9]+]]
391
392; GCN-NEXT: [[LONGBB:BB[0-9]+_[0-9]+]]: ; %entry
393; GCN-NEXT: s_getpc_b64 vcc
394; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[BB2:BB[0-9]_[0-9]+]]-([[LONGBB]]+4)
395; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0{{$}}
396; GCN-NEXT: s_setpc_b64 vcc
397
398; GCN-NEXT: [[IF]]: ; %if
399; GCN: buffer_store_dword
400; GCN: s_cmp_lg_u32
401; GCN: s_cbranch_scc1 [[ENDIF]]
402
403; GCN-NEXT: ; BB#2: ; %if_uniform
404; GCN: buffer_store_dword
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000405
406; GCN-NEXT: [[ENDIF]]: ; %endif
407; GCN-NEXT: s_or_b64 exec, exec, [[MASK]]
Kyle Buttb15c0662017-01-31 23:48:32 +0000408; GCN-NEXT: s_sleep 5
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000409; GCN-NEXT: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000410define amdgpu_kernel void @uniform_inside_divergent(i32 addrspace(1)* %out, i32 %cond) #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000411entry:
412 %tid = call i32 @llvm.amdgcn.workitem.id.x()
413 %d_cmp = icmp ult i32 %tid, 16
414 br i1 %d_cmp, label %if, label %endif
415
416if:
417 store i32 0, i32 addrspace(1)* %out
418 %u_cmp = icmp eq i32 %cond, 0
419 br i1 %u_cmp, label %if_uniform, label %endif
420
421if_uniform:
422 store i32 1, i32 addrspace(1)* %out
423 br label %endif
424
425endif:
Kyle Buttb15c0662017-01-31 23:48:32 +0000426 ; layout can remove the split branch if it can copy the return block.
427 ; This call makes the return block long enough that it doesn't get copied.
428 call void @llvm.amdgcn.s.sleep(i32 5);
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000429 ret void
430}
431
432; si_mask_branch
433; s_cbranch_execz
434; s_branch
435
436; GCN-LABEL: {{^}}analyze_mask_branch:
437; GCN: v_cmp_lt_f32_e32 vcc
438; GCN-NEXT: s_and_saveexec_b64 [[MASK:s\[[0-9]+:[0-9]+\]]], vcc
439; GCN-NEXT: s_xor_b64 [[MASK]], exec, [[MASK]]
440; GCN-NEXT: ; mask branch [[RET:BB[0-9]+_[0-9]+]]
Tobias Grosser02d86b82017-03-02 21:47:51 +0000441; GCN-NEXT: s_cbranch_execz [[BRANCH_SKIP:BB[0-9]+_[0-9]+]]
442; GCN-NEXT: s_branch [[LOOP_BODY:BB[0-9]+_[0-9]+]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000443
Tobias Grosser02d86b82017-03-02 21:47:51 +0000444; GCN-NEXT: [[BRANCH_SKIP]]: ; %entry
Matt Arsenault103af902017-03-01 03:36:04 +0000445; GCN-NEXT: s_getpc_b64 vcc
446; GCN-NEXT: s_add_u32 vcc_lo, vcc_lo, [[RET]]-([[BRANCH_SKIP]]+4)
447; GCN-NEXT: s_addc_u32 vcc_hi, vcc_hi, 0
448; GCN-NEXT: s_setpc_b64 vcc
449
450; GCN-NEXT: [[LOOP_BODY]]: ; %loop_body
Tobias Grosser02d86b82017-03-02 21:47:51 +0000451; GCN: s_mov_b64 vcc, -1{{$}}
Matthias Braun325cd2c2016-11-11 01:34:21 +0000452; GCN: ;;#ASMSTART
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000453; GCN: v_nop_e64
454; GCN: v_nop_e64
455; GCN: v_nop_e64
456; GCN: v_nop_e64
457; GCN: v_nop_e64
458; GCN: v_nop_e64
459; GCN: ;;#ASMEND
Tobias Grosser02d86b82017-03-02 21:47:51 +0000460; GCN-NEXT: s_cbranch_vccz [[RET]]
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000461
462; GCN-NEXT: [[LONGBB:BB[0-9]+_[0-9]+]]: ; %loop_body
463; GCN-NEXT: ; in Loop: Header=[[LOOP_BODY]] Depth=1
464; GCN-NEXT: s_getpc_b64 vcc
465; GCN-NEXT: s_sub_u32 vcc_lo, vcc_lo, ([[LONGBB]]+4)-[[LOOP_BODY]]
466; GCN-NEXT: s_subb_u32 vcc_hi, vcc_hi, 0
467; GCN-NEXT: s_setpc_b64 vcc
468
Tobias Grosser02d86b82017-03-02 21:47:51 +0000469; GCN-NEXT: [[RET]]: ; %Flow
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000470; GCN-NEXT: s_or_b64 exec, exec, [[MASK]]
471; GCN: buffer_store_dword
472; GCN-NEXT: s_endpgm
Matt Arsenault3dbeefa2017-03-21 21:39:51 +0000473define amdgpu_kernel void @analyze_mask_branch() #0 {
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000474entry:
475 %reg = call float asm sideeffect "v_mov_b32_e64 $0, 0", "=v"()
476 %cmp0 = fcmp ogt float %reg, 0.000000e+00
477 br i1 %cmp0, label %loop, label %ret
Matt Arsenault103af902017-03-01 03:36:04 +0000478
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000479loop:
480 %phi = phi float [ 0.000000e+00, %loop_body ], [ 1.000000e+00, %entry ]
481 call void asm sideeffect
482 "v_nop_e64
483 v_nop_e64", ""() #0
484 %cmp1 = fcmp olt float %phi, 8.0
485 br i1 %cmp1, label %loop_body, label %ret
486
487loop_body:
488 call void asm sideeffect
489 "v_nop_e64
490 v_nop_e64
491 v_nop_e64
492 v_nop_e64", ""() #0
493 br label %loop
494
495ret:
496 store volatile i32 7, i32 addrspace(1)* undef
497 ret void
498}
499
Matt Arsenault44deb792016-11-02 16:18:29 +0000500; GCN-LABEL: {{^}}long_branch_hang:
501; GCN: s_cmp_lt_i32 s{{[0-9]+}}, 6
Kyle Butt7fbec9b2017-02-15 19:49:14 +0000502; GCN-NEXT: s_cbranch_scc1 {{BB[0-9]+_[0-9]+}}
503; GCN-NEXT: s_branch [[LONG_BR_0:BB[0-9]+_[0-9]+]]
Matt Arsenaultad55ee52016-12-06 01:02:51 +0000504; GCN-NEXT: BB{{[0-9]+_[0-9]+}}:
Matt Arsenault44deb792016-11-02 16:18:29 +0000505
506; GCN: s_add_u32 vcc_lo, vcc_lo, [[LONG_BR_DEST0:BB[0-9]+_[0-9]+]]-(
507; GCN: s_setpc_b64
508
Matt Arsenaultad55ee52016-12-06 01:02:51 +0000509; GCN-NEXT: [[LONG_BR_0]]:
Matt Arsenault44deb792016-11-02 16:18:29 +0000510; GCN-DAG: v_cmp_lt_i32
511; GCN-DAG: v_cmp_gt_i32
512; GCN: s_cbranch_vccnz
513
514; GCN: s_setpc_b64
515; GCN: s_setpc_b64
516
Matt Arsenaultf530e8b2016-11-07 19:09:33 +0000517; GCN: [[LONG_BR_DEST0]]
Stanislav Mekhanoshin0ee250e2016-11-28 18:58:49 +0000518; GCN: v_cmp_ne_u32_e32
Stanislav Mekhanoshin0ee250e2016-11-28 18:58:49 +0000519; GCN-NEXT: s_cbranch_vccz
Matt Arsenault44deb792016-11-02 16:18:29 +0000520; GCN: s_setpc_b64
521
522; GCN: s_endpgm
523define amdgpu_kernel void @long_branch_hang(i32 addrspace(1)* nocapture %arg, i32 %arg1, i32 %arg2, i32 %arg3, i32 %arg4, i64 %arg5) #0 {
524bb:
525 %tmp = icmp slt i32 %arg2, 9
526 %tmp6 = icmp eq i32 %arg1, 0
527 %tmp7 = icmp sgt i32 %arg4, 0
528 %tmp8 = icmp sgt i32 %arg4, 5
529 br i1 %tmp8, label %bb9, label %bb13
530
531bb9: ; preds = %bb
532 %tmp10 = and i1 %tmp7, %tmp
533 %tmp11 = icmp slt i32 %arg3, %arg4
534 %tmp12 = or i1 %tmp11, %tmp7
535 br i1 %tmp12, label %bb19, label %bb14
536
537bb13: ; preds = %bb
538 br i1 %tmp6, label %bb19, label %bb14
539
540bb14: ; preds = %bb13, %bb9
541 %tmp15 = icmp slt i32 %arg3, %arg4
542 %tmp16 = or i1 %tmp15, %tmp
543 %tmp17 = and i1 %tmp6, %tmp16
544 %tmp18 = zext i1 %tmp17 to i32
545 br label %bb19
546
547bb19: ; preds = %bb14, %bb13, %bb9
548 %tmp20 = phi i32 [ undef, %bb9 ], [ undef, %bb13 ], [ %tmp18, %bb14 ]
549 %tmp21 = getelementptr inbounds i32, i32 addrspace(1)* %arg, i64 %arg5
550 store i32 %tmp20, i32 addrspace(1)* %tmp21, align 4
551 ret void
552}
553
Matt Arsenault6bc43d82016-10-06 16:20:41 +0000554attributes #0 = { nounwind }
555attributes #1 = { nounwind readnone }