1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2# RUN: llc -march=amdgcn -verify-machineinstrs -run-pass=si-lower-control-flow -amdgpu-remove-redundant-endcf %s -o - | FileCheck -check-prefix=GCN %s
3
4# Make sure dbg_value doesn't change codeegn when collapsing end_cf
5---
6name: simple_nested_if_dbg_value
7tracksRegLiveness: true
8machineFunctionInfo:
9  isEntryFunction: true
10body:             |
11  ; GCN-LABEL: name: simple_nested_if_dbg_value
12  ; GCN: bb.0:
13  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
14  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
15  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
16  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
17  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
18  ; GCN: bb.1:
19  ; GCN:   successors: %bb.2(0x40000000), %bb.4(0x40000000)
20  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
21  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
22  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
23  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
24  ; GCN: bb.2:
25  ; GCN:   successors: %bb.4(0x80000000)
26  ; GCN: bb.4:
27  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
28  ; GCN:   DBG_VALUE
29  ; GCN:   S_ENDPGM 0
30  bb.0:
31    successors: %bb.1, %bb.4
32
33    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
34
35  bb.1:
36    successors: %bb.2, %bb.3
37
38    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
39
40  bb.2:
41
42  bb.3:
43    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
44    DBG_VALUE
45
46  bb.4:
47    DBG_VALUE
48    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
49    S_ENDPGM 0
50
51...
52
53# Empty block separates the collapsable s_or_b64
54---
55name: simple_nested_if_empty_block_between
56tracksRegLiveness: true
57machineFunctionInfo:
58  isEntryFunction: true
59body:             |
60  ; GCN-LABEL: name: simple_nested_if_empty_block_between
61  ; GCN: bb.0:
62  ; GCN:   successors: %bb.5(0x40000000), %bb.1(0x40000000)
63  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
64  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
65  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
66  ; GCN:   S_CBRANCH_EXECZ %bb.5, implicit $exec
67  ; GCN: bb.1:
68  ; GCN:   successors: %bb.2(0x40000000), %bb.4(0x40000000)
69  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
70  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
71  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
72  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
73  ; GCN: bb.2:
74  ; GCN:   successors: %bb.4(0x80000000)
75  ; GCN: bb.4:
76  ; GCN:   successors: %bb.5(0x80000000)
77  ; GCN: bb.5:
78  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
79  ; GCN:   S_ENDPGM 0
80  bb.0:
81    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
82
83  bb.1:
84    successors: %bb.2, %bb.3
85
86    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
87
88  bb.2:
89
90  bb.3:
91    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
92
93  bb.5:
94
95  bb.4:
96    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
97    S_ENDPGM 0
98
99...
100
101# Effectively empty block separates the collapsable s_or_b64
102---
103name: simple_nested_if_empty_block_dbg_between
104tracksRegLiveness: true
105machineFunctionInfo:
106  isEntryFunction: true
107body:             |
108  ; GCN-LABEL: name: simple_nested_if_empty_block_dbg_between
109  ; GCN: bb.0:
110  ; GCN:   successors: %bb.1(0x40000000), %bb.5(0x40000000)
111  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
112  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
113  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
114  ; GCN:   S_CBRANCH_EXECZ %bb.5, implicit $exec
115  ; GCN: bb.1:
116  ; GCN:   successors: %bb.2(0x40000000), %bb.4(0x40000000)
117  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
118  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
119  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
120  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
121  ; GCN: bb.2:
122  ; GCN:   successors: %bb.4(0x80000000)
123  ; GCN: bb.4:
124  ; GCN:   successors: %bb.5(0x80000000)
125  ; GCN:   DBG_VALUE
126  ; GCN: bb.5:
127  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
128  ; GCN:   S_ENDPGM 0
129  bb.0:
130    successors: %bb.1, %bb.4
131
132    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
133
134  bb.1:
135    successors: %bb.2, %bb.3
136
137    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
138
139  bb.2:
140
141  bb.3:
142    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
143
144  bb.5:
145    DBG_VALUE
146
147  bb.4:
148    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
149    S_ENDPGM 0
150
151...
152
153---
154name: skip_salu_and_meta_insts_find_first
155tracksRegLiveness: true
156machineFunctionInfo:
157  isEntryFunction: true
158body:             |
159  ; GCN-LABEL: name: skip_salu_and_meta_insts_find_first
160  ; GCN: bb.0:
161  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
162  ; GCN:   liveins: $vgpr0, $sgpr0_sgpr1
163  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
164  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
165  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
166  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
167  ; GCN: bb.1:
168  ; GCN:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
169  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
170  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
171  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
172  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
173  ; GCN: bb.2:
174  ; GCN:   successors: %bb.3(0x80000000)
175  ; GCN: bb.3:
176  ; GCN:   successors: %bb.4(0x80000000)
177  ; GCN:   [[DEF:%[0-9]+]]:sgpr_32 = IMPLICIT_DEF
178  ; GCN:   [[S_BREV_B32_:%[0-9]+]]:sgpr_32 = S_BREV_B32 [[DEF]]
179  ; GCN:   KILL [[DEF]]
180  ; GCN: bb.4:
181  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
182  ; GCN:   S_ENDPGM 0
183  bb.0:
184    successors: %bb.1, %bb.4
185    liveins: $vgpr0, $sgpr0_sgpr1
186
187    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
188
189  bb.1:
190    successors: %bb.2, %bb.3
191
192    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
193
194  bb.2:
195
196  bb.3:
197    %4:sgpr_32 = IMPLICIT_DEF
198    %5:sgpr_32 = S_BREV_B32 %4
199    KILL %4
200    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
201
202  bb.4:
203    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
204    S_ENDPGM 0
205
206...
207
208# Make sure SALU instructions, meta instructions, and SGPR->SGPR
209# copies are skipped.
210---
211name: skip_salu_and_meta_insts_after
212tracksRegLiveness: true
213machineFunctionInfo:
214  isEntryFunction: true
215body:             |
216  ; GCN-LABEL: name: skip_salu_and_meta_insts_after
217  ; GCN: bb.0:
218  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
219  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
220  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
221  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
222  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
223  ; GCN: bb.1:
224  ; GCN:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
225  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
226  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
227  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
228  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
229  ; GCN: bb.2:
230  ; GCN:   successors: %bb.3(0x80000000)
231  ; GCN: bb.3:
232  ; GCN:   successors: %bb.4(0x80000000)
233  ; GCN:   [[DEF:%[0-9]+]]:sgpr_32 = IMPLICIT_DEF
234  ; GCN:   [[S_BREV_B32_:%[0-9]+]]:sgpr_32 = S_BREV_B32 [[DEF]]
235  ; GCN:   KILL [[DEF]]
236  ; GCN:   [[COPY2:%[0-9]+]]:sgpr_32 = COPY [[S_BREV_B32_]]
237  ; GCN: bb.4:
238  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
239  ; GCN:   S_ENDPGM 0
240  bb.0:
241    successors: %bb.1, %bb.4
242
243    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
244
245  bb.1:
246    successors: %bb.2, %bb.3
247
248    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
249
250  bb.2:
251
252  bb.3:
253    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
254    %4:sgpr_32 = IMPLICIT_DEF
255    %5:sgpr_32 = S_BREV_B32 %4
256    KILL %4
257    %6:sgpr_32 = COPY %5
258
259  bb.4:
260    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
261    S_ENDPGM 0
262
263...
264
265# SALU instruction depends on exec through a normal operand.
266---
267name: salu_exec_dependency
268tracksRegLiveness: true
269machineFunctionInfo:
270  isEntryFunction: true
271body:             |
272  ; GCN-LABEL: name: salu_exec_dependency
273  ; GCN: bb.0:
274  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
275  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
276  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
277  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
278  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
279  ; GCN: bb.1:
280  ; GCN:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
281  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
282  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
283  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
284  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
285  ; GCN: bb.2:
286  ; GCN:   successors: %bb.3(0x80000000)
287  ; GCN: bb.3:
288  ; GCN:   successors: %bb.4(0x80000000)
289  ; GCN:   $exec = S_OR_B64 $exec, [[COPY1]], implicit-def $scc
290  ; GCN:   [[S_BREV_B64_:%[0-9]+]]:sreg_64 = S_BREV_B64 $exec
291  ; GCN: bb.4:
292  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
293  ; GCN:   S_ENDPGM 0
294  bb.0:
295    successors: %bb.1, %bb.4
296
297    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
298
299  bb.1:
300    successors: %bb.2, %bb.3
301
302    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
303
304  bb.2:
305
306  bb.3:
307    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
308    %4:sreg_64 = S_BREV_B64 $exec
309
310  bb.4:
311    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
312    S_ENDPGM 0
313
314...
315
316# Copy to / from VGPR should be assumed to read exec
317---
318name: copy_no_explicit_exec_dependency
319tracksRegLiveness: true
320machineFunctionInfo:
321  isEntryFunction: true
322body:             |
323  ; GCN-LABEL: name: copy_no_explicit_exec_dependency
324  ; GCN: bb.0:
325  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
326  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
327  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
328  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
329  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
330  ; GCN: bb.1:
331  ; GCN:   successors: %bb.2(0x40000000), %bb.3(0x40000000)
332  ; GCN:   [[DEF:%[0-9]+]]:vreg_128 = IMPLICIT_DEF
333  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
334  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %4:sreg_64, implicit-def dead $scc
335  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
336  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
337  ; GCN: bb.2:
338  ; GCN:   successors: %bb.3(0x80000000)
339  ; GCN: bb.3:
340  ; GCN:   successors: %bb.4(0x80000000)
341  ; GCN:   $exec = S_OR_B64 $exec, [[COPY1]], implicit-def $scc
342  ; GCN:   [[COPY2:%[0-9]+]]:vgpr_32 = COPY [[DEF]].sub2
343  ; GCN: bb.4:
344  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
345  ; GCN:   S_ENDPGM 0
346  bb.0:
347    successors: %bb.1, %bb.4
348
349    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
350
351  bb.1:
352    successors: %bb.2, %bb.3
353
354    %2:vreg_128 = IMPLICIT_DEF
355    %3:sreg_64 = SI_IF undef %4:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
356
357  bb.2:
358
359  bb.3:
360    SI_END_CF %3:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
361    %5:vgpr_32 = COPY %2.sub2
362
363  bb.4:
364    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
365    S_ENDPGM 0
366
367...
368
369---
370name: simple_nested_if_not_layout_successor
371tracksRegLiveness: true
372machineFunctionInfo:
373  isEntryFunction: true
374body:             |
375  ; GCN-LABEL: name: simple_nested_if_not_layout_successor
376  ; GCN: bb.0:
377  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
378  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
379  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
380  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
381  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
382  ; GCN: bb.1:
383  ; GCN:   successors: %bb.2(0x40000000), %bb.5(0x40000000)
384  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
385  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
386  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
387  ; GCN:   S_CBRANCH_EXECZ %bb.5, implicit $exec
388  ; GCN: bb.2:
389  ; GCN:   successors: %bb.5(0x80000000)
390  ; GCN: bb.5:
391  ; GCN:   successors: %bb.4(0x80000000)
392  ; GCN:   S_BRANCH %bb.4
393  ; GCN: bb.4:
394  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
395  ; GCN:   S_ENDPGM 0
396  bb.0:
397    successors: %bb.1, %bb.4
398
399    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
400
401  bb.1:
402    successors: %bb.2, %bb.3
403
404    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
405
406  bb.2:
407
408  bb.3:
409    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
410    S_BRANCH %bb.5
411
412  bb.4:
413    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
414    S_ENDPGM 0
415
416  bb.5:
417    S_BRANCH %bb.4
418
419...
420
421# This should never happen, but check that we do not hang anyway
422
423---
424name: resursive_endcf
425tracksRegLiveness: true
426liveins:
427  - { reg: '$vgpr0', virtual-reg: '%0' }
428machineFunctionInfo:
429  isEntryFunction: true
430body:             |
431  ; GCN-LABEL: name: resursive_endcf
432  ; GCN: bb.0:
433  ; GCN:   successors: %bb.1(0x80000000)
434  ; GCN:   liveins: $vgpr0
435  ; GCN:   [[COPY:%[0-9]+]]:vgpr_32 = COPY $vgpr0
436  ; GCN:   [[V_CMP_LT_U32_e64_:%[0-9]+]]:sreg_64 = V_CMP_LT_U32_e64 1, [[COPY]], implicit $exec
437  ; GCN: bb.1:
438  ; GCN:   successors: %bb.1(0x80000000)
439  ; GCN:   $exec = S_OR_B64 $exec, [[V_CMP_LT_U32_e64_]], implicit-def $scc
440  ; GCN:   S_BRANCH %bb.1
441  bb.0:
442    successors: %bb.1
443    liveins: $vgpr0
444
445    %0:vgpr_32 = COPY $vgpr0
446    %2:sreg_64 = V_CMP_LT_U32_e64 1, %0, implicit $exec
447
448  bb.1:
449    successors: %bb.1
450
451    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
452    S_BRANCH %bb.1
453
454...
455
456# Both s_or_b64 shall be preserved since the outer SI_END_CF belongs to SI_ELSE.
457
458---
459name: simple_outer_if_else
460tracksRegLiveness: true
461machineFunctionInfo:
462  isEntryFunction: true
463body:             |
464  ; GCN-LABEL: name: simple_outer_if_else
465  ; GCN: bb.0:
466  ; GCN:   successors: %bb.1(0x40000000), %bb.2(0x40000000)
467  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
468  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
469  ; GCN:   [[S_XOR_B64_:%[0-9]+]]:sreg_64 = S_XOR_B64 [[S_AND_B64_]], [[COPY]], implicit-def dead $scc
470  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
471  ; GCN:   S_CBRANCH_EXECZ %bb.2, implicit $exec
472  ; GCN: bb.1:
473  ; GCN:   successors: %bb.2(0x80000000)
474  ; GCN:   S_BRANCH %bb.2
475  ; GCN: bb.2:
476  ; GCN:   successors: %bb.3(0x40000000), %bb.6(0x40000000)
477  ; GCN:   [[S_OR_SAVEEXEC_B64_:%[0-9]+]]:sreg_64 = S_OR_SAVEEXEC_B64 [[S_XOR_B64_]], implicit-def $exec, implicit-def $scc, implicit $exec
478  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 $exec, [[S_OR_SAVEEXEC_B64_]], implicit-def $scc
479  ; GCN:   $exec = S_XOR_B64_term $exec, [[S_AND_B64_1]], implicit-def $scc
480  ; GCN:   S_CBRANCH_EXECZ %bb.6, implicit $exec
481  ; GCN: bb.3:
482  ; GCN:   successors: %bb.3(0x40000000), %bb.4(0x40000000)
483  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
484  ; GCN:   [[S_AND_B64_2:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %4:sreg_64, implicit-def dead $scc
485  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_2]]
486  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
487  ; GCN: bb.4:
488  ; GCN:   successors: %bb.5(0x80000000)
489  ; GCN: bb.5:
490  ; GCN:   successors: %bb.6(0x80000000)
491  ; GCN:   $exec = S_OR_B64 $exec, [[COPY1]], implicit-def $scc
492  ; GCN: bb.6:
493  ; GCN:   $exec = S_OR_B64 $exec, [[S_AND_B64_1]], implicit-def $scc
494  ; GCN:   S_ENDPGM 0
495  bb.0:
496    successors: %bb.1, %bb.2
497
498    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.2, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
499
500  bb.1:
501    successors: %bb.2
502    S_BRANCH %bb.2
503
504  bb.2:
505    successors: %bb.3, %bb.6
506    %2:sreg_64 = SI_ELSE %0:sreg_64, %bb.6, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
507
508  bb.3:
509    successors: %bb.3, %bb.4
510
511    %3:sreg_64 = SI_IF undef %4:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
512
513  bb.4:
514    successors: %bb.5
515
516  bb.5:
517    successors: %bb.6
518
519    SI_END_CF %3:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
520
521  bb.6:
522    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
523    S_ENDPGM 0
524
525...
526
527---
528name: if_inside_loop
529tracksRegLiveness: true
530machineFunctionInfo:
531  isEntryFunction: true
532body:             |
533  ; GCN-LABEL: name: if_inside_loop
534  ; GCN: bb.0:
535  ; GCN:   successors: %bb.6(0x80000000)
536  ; GCN:   S_BRANCH %bb.6
537  ; GCN: bb.1:
538  ; GCN:   successors: %bb.3(0x40000000), %bb.2(0x40000000)
539  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
540  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
541  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
542  ; GCN:   S_CBRANCH_EXECZ %bb.3, implicit $exec
543  ; GCN: bb.2:
544  ; GCN:   successors: %bb.6(0x80000000)
545  ; GCN:   S_BRANCH %bb.6
546  ; GCN: bb.3:
547  ; GCN:   successors: %bb.4(0x80000000)
548  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
549  ; GCN: bb.4:
550  ; GCN:   successors: %bb.5(0x80000000)
551  ; GCN:   $exec = S_OR_B64 $exec, %2, implicit-def $scc
552  ; GCN: bb.5:
553  ; GCN:   successors: %bb.6(0x80000000)
554  ; GCN: bb.6:
555  ; GCN:   successors: %bb.4(0x40000000), %bb.0(0x40000000)
556  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
557  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
558  ; GCN:   [[S_XOR_B64_:%[0-9]+]]:sreg_64 = S_XOR_B64 [[S_AND_B64_1]], [[COPY1]], implicit-def dead $scc
559  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
560  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
561  ; GCN:   S_BRANCH %bb.0
562  ; GCN:   S_ENDPGM 0
563  bb.0:
564    S_BRANCH %bb.6
565
566  bb.1:
567    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
568
569  bb.2:
570    S_BRANCH %bb.6
571
572  bb.3:
573    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
574
575  bb.4:
576    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
577
578  bb.5:
579
580  bb.6:
581    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
582    S_BRANCH %bb.0
583    S_ENDPGM 0
584
585...
586
587---
588# redundant MBB removal correctness test:
589# we can keep bb.2 fallthrough to the  new succ because after bb.3 gets removed
590# new succ (bb.4) becomes bb.2's layout successor
591name: removed_succ_fallthrough_but_layout_successor
592tracksRegLiveness: true
593machineFunctionInfo:
594  isEntryFunction: true
595body:             |
596  ; GCN-LABEL: name: removed_succ_fallthrough_but_layout_successor
597  ; GCN: bb.0:
598  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
599  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
600  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
601  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
602  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
603  ; GCN: bb.1:
604  ; GCN:   successors: %bb.2(0x40000000), %bb.4(0x40000000)
605  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
606  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
607  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
608  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
609  ; GCN: bb.2:
610  ; GCN:   successors: %bb.4(0x80000000)
611  ; GCN: bb.4:
612  ; GCN:   successors: %bb.5(0x80000000)
613  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
614  ; GCN: bb.5:
615  ; GCN:   S_ENDPGM 0
616  bb.0:
617    successors: %bb.1, %bb.4
618
619    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
620
621  bb.1:
622    successors: %bb.2, %bb.3
623
624    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
625
626  bb.2:
627
628  bb.3:
629    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
630
631
632  bb.4:
633    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
634
635  bb.5:
636    S_ENDPGM 0
637
638...
639
640---
641# redundant MBB removal correctness test:
642# If one of the remdundant block preds has a fallthrough path, but the only redundant block succ is not
643# going to be a layout successor to that pred after redundant block removal, we should not rearrange
644# blocks to keep pred's fallthrough path, if the succ has fallthrough path to one of it's succ too.
645
646name: deleted_succ_fallthrough_not_layout_successor
647tracksRegLiveness: true
648machineFunctionInfo:
649  isEntryFunction: true
650body:             |
651  ; GCN-LABEL: name: deleted_succ_fallthrough_not_layout_successor
652  ; GCN: bb.0:
653  ; GCN:   successors: %bb.1(0x40000000), %bb.4(0x40000000)
654  ; GCN:   [[COPY:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
655  ; GCN:   [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY]], undef %1:sreg_64, implicit-def dead $scc
656  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_]]
657  ; GCN:   S_CBRANCH_EXECZ %bb.4, implicit $exec
658  ; GCN: bb.1:
659  ; GCN:   successors: %bb.2(0x40000000), %bb.5(0x40000000)
660  ; GCN:   [[COPY1:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
661  ; GCN:   [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY1]], undef %3:sreg_64, implicit-def dead $scc
662  ; GCN:   $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
663  ; GCN:   S_CBRANCH_EXECZ %bb.5, implicit $exec
664  ; GCN: bb.2:
665  ; GCN:   successors: %bb.5(0x80000000)
666  ; GCN:   S_BRANCH %bb.5
667  ; GCN: bb.4:
668  ; GCN:   S_ENDPGM 0
669  ; GCN: bb.5:
670  ; GCN:   successors: %bb.6(0x80000000)
671  ; GCN:   $exec = S_OR_B64 $exec, [[COPY]], implicit-def $scc
672  ; GCN: bb.6:
673  ; GCN:   successors: %bb.4(0x80000000)
674  ; GCN:   S_BRANCH %bb.4
675  bb.0:
676    successors: %bb.1, %bb.4
677
678    %0:sreg_64 = SI_IF undef %1:sreg_64, %bb.4, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
679
680  bb.1:
681    successors: %bb.2, %bb.3
682
683    %2:sreg_64 = SI_IF undef %3:sreg_64, %bb.3, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
684
685  bb.2:
686
687  bb.3:
688    SI_END_CF %2:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
689    S_BRANCH %bb.5
690
691  bb.4:
692    S_ENDPGM 0
693
694
695  bb.5:
696    SI_END_CF %0:sreg_64, implicit-def dead $exec, implicit-def dead $scc, implicit $exec
697
698  bb.6:
699    S_BRANCH %bb.4
700
701...
702