1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple=amdgcn -mcpu=fiji -verify-machineinstrs -run-pass=si-lower-control-flow -o - %s | FileCheck %s
4 # Test si-lower-control-flow insertion points when other terminator
5 # instructions are present besides the control flow pseudo and a
9 # There's another terminator instruction between SI_IF and
10 # S_BRANCH. The S_CBRANCH_EXECZ should be inserted immediately before
13 name: other_terminator_sbranch_after_si_if
14 tracksRegLiveness: true
16 ; CHECK-LABEL: name: other_terminator_sbranch_after_si_if
18 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.1(0x40000000)
19 ; CHECK-NEXT: liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
21 ; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
22 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sreg_64_xexec = COPY $sgpr4_sgpr5
23 ; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 0, [[COPY]], implicit $exec
24 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
25 ; CHECK-NEXT: [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY2]], [[V_CMP_EQ_U32_e64_]], implicit-def dead $scc
26 ; CHECK-NEXT: [[S_XOR_B64_:%[0-9]+]]:sreg_64_xexec = S_XOR_B64 [[S_AND_B64_]], [[COPY2]], implicit-def dead $scc
27 ; CHECK-NEXT: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
28 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term killed [[COPY1]], implicit $exec
29 ; CHECK-NEXT: S_CBRANCH_EXECZ %bb.1, implicit $exec
30 ; CHECK-NEXT: S_BRANCH %bb.2
33 ; CHECK-NEXT: successors: %bb.2(0x80000000)
35 ; CHECK-NEXT: S_BRANCH %bb.2
38 ; CHECK-NEXT: S_ENDPGM 0, implicit [[S_MOV_B64_term]]
40 successors: %bb.2, %bb.1
41 liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
43 %0:vgpr_32 = COPY killed $vgpr0
44 %1:sreg_64_xexec = COPY $sgpr4_sgpr5
45 %2:sreg_64_xexec = V_CMP_EQ_U32_e64 0, %0, implicit $exec
46 %3:sreg_64_xexec = SI_IF %2, %bb.1, implicit-def $exec, implicit-def dead $scc, implicit $exec
47 %4:sreg_64_xexec = S_MOV_B64_term killed %1, implicit $exec
54 S_ENDPGM 0, implicit %4
58 # S_CBRANCH_EXECZ should be inserted after the other terminator
60 name: other_terminator_fallthrough_after_si_if
61 tracksRegLiveness: true
63 ; CHECK-LABEL: name: other_terminator_fallthrough_after_si_if
65 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.1(0x40000000)
66 ; CHECK-NEXT: liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
68 ; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
69 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sreg_64_xexec = COPY $sgpr4_sgpr5
70 ; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 0, [[COPY]], implicit $exec
71 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
72 ; CHECK-NEXT: [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY2]], [[V_CMP_EQ_U32_e64_]], implicit-def dead $scc
73 ; CHECK-NEXT: [[S_XOR_B64_:%[0-9]+]]:sreg_64_xexec = S_XOR_B64 [[S_AND_B64_]], [[COPY2]], implicit-def dead $scc
74 ; CHECK-NEXT: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
75 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term killed [[COPY1]], implicit $exec
76 ; CHECK-NEXT: S_CBRANCH_EXECZ %bb.2, implicit $exec
79 ; CHECK-NEXT: successors: %bb.2(0x80000000)
81 ; CHECK-NEXT: S_BRANCH %bb.2
84 ; CHECK-NEXT: S_ENDPGM 0, implicit [[S_MOV_B64_term]]
86 successors: %bb.2, %bb.1
87 liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
89 %0:vgpr_32 = COPY killed $vgpr0
90 %1:sreg_64_xexec = COPY $sgpr4_sgpr5
91 %2:sreg_64_xexec = V_CMP_EQ_U32_e64 0, %0, implicit $exec
92 %3:sreg_64_xexec = SI_IF %2, %bb.2, implicit-def $exec, implicit-def dead $scc, implicit $exec
93 %4:sreg_64_xexec = S_MOV_B64_term killed %1, implicit $exec
99 S_ENDPGM 0, implicit %4
104 name: other_terminator_sbranch_after_si_else
105 tracksRegLiveness: true
107 ; CHECK-LABEL: name: other_terminator_sbranch_after_si_else
109 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.1(0x40000000)
110 ; CHECK-NEXT: liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
112 ; CHECK-NEXT: [[S_OR_SAVEEXEC_B64_:%[0-9]+]]:sreg_64 = S_OR_SAVEEXEC_B64 %2, implicit-def $exec, implicit-def $scc, implicit $exec
113 ; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
114 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sreg_64_xexec = COPY $sgpr4_sgpr5
115 ; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 0, [[COPY]], implicit $exec
116 ; CHECK-NEXT: [[S_AND_B64_:%[0-9]+]]:sreg_64_xexec = S_AND_B64 $exec, [[S_OR_SAVEEXEC_B64_]], implicit-def $scc
117 ; CHECK-NEXT: $exec = S_XOR_B64_term $exec, [[S_AND_B64_]], implicit-def $scc
118 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term killed [[COPY1]], implicit $exec
119 ; CHECK-NEXT: S_CBRANCH_EXECZ %bb.1, implicit $exec
120 ; CHECK-NEXT: S_BRANCH %bb.2
123 ; CHECK-NEXT: successors: %bb.2(0x80000000)
125 ; CHECK-NEXT: S_BRANCH %bb.2
128 ; CHECK-NEXT: S_ENDPGM 0, implicit [[S_MOV_B64_term]]
130 successors: %bb.2, %bb.1
131 liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
133 %0:vgpr_32 = COPY killed $vgpr0
134 %1:sreg_64_xexec = COPY $sgpr4_sgpr5
135 %2:sreg_64_xexec = V_CMP_EQ_U32_e64 0, %0, implicit $exec
136 %3:sreg_64_xexec = SI_ELSE %2, %bb.1, implicit-def $exec, implicit-def dead $scc, implicit $exec
137 %4:sreg_64_xexec = S_MOV_B64_term killed %1, implicit $exec
144 S_ENDPGM 0, implicit %4
149 name: other_terminator_sbranch_after_si_loop
150 tracksRegLiveness: true
152 ; CHECK-LABEL: name: other_terminator_sbranch_after_si_loop
154 ; CHECK-NEXT: successors: %bb.2(0x40000000), %bb.1(0x40000000)
155 ; CHECK-NEXT: liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
157 ; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
158 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:sreg_64_xexec = COPY $sgpr4_sgpr5
159 ; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 0, [[COPY]], implicit $exec
160 ; CHECK-NEXT: $exec = S_ANDN2_B64_term $exec, [[V_CMP_EQ_U32_e64_]], implicit-def $scc
161 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term killed [[COPY1]], implicit $exec
162 ; CHECK-NEXT: S_CBRANCH_EXECNZ %bb.1, implicit $exec
163 ; CHECK-NEXT: S_BRANCH %bb.2
166 ; CHECK-NEXT: successors: %bb.2(0x80000000)
168 ; CHECK-NEXT: S_BRANCH %bb.2
171 ; CHECK-NEXT: S_ENDPGM 0, implicit [[S_MOV_B64_term]]
173 successors: %bb.2, %bb.1
174 liveins: $vgpr0, $vgpr1, $sgpr4_sgpr5
176 %0:vgpr_32 = COPY killed $vgpr0
177 %1:sreg_64_xexec = COPY $sgpr4_sgpr5
178 %2:sreg_64_xexec = V_CMP_EQ_U32_e64 0, %0, implicit $exec
179 SI_LOOP %2, %bb.1, implicit-def $exec, implicit-def dead $scc, implicit $exec
180 %4:sreg_64_xexec = S_MOV_B64_term killed %1, implicit $exec
187 S_ENDPGM 0, implicit %4
191 # The save exec result register of SI_IF is used by other terminators
192 # inserted to behave as a lowered phi. The output register of SI_IF
193 # was ignored, and the def was removed, so the S_MOV_B64_term uses
194 # would fail the verifier.
200 regBankSelected: true
202 tracksRegLiveness: true
204 ; CHECK-LABEL: name: si_if_use
206 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
207 ; CHECK-NEXT: liveins: $vgpr0, $vgpr1, $sgpr30_sgpr31
209 ; CHECK-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY killed $vgpr0
210 ; CHECK-NEXT: [[COPY1:%[0-9]+]]:vgpr_32 = COPY killed $vgpr1
211 ; CHECK-NEXT: [[V_CMP_EQ_U32_e64_:%[0-9]+]]:sreg_64_xexec = V_CMP_EQ_U32_e64 killed [[COPY]], killed [[COPY1]], implicit $exec
212 ; CHECK-NEXT: [[COPY2:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
213 ; CHECK-NEXT: [[S_AND_B64_:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY2]], [[V_CMP_EQ_U32_e64_]], implicit-def dead $scc
214 ; CHECK-NEXT: [[S_XOR_B64_:%[0-9]+]]:sreg_64_xexec = S_XOR_B64 [[S_AND_B64_]], [[COPY2]], implicit-def dead $scc
215 ; CHECK-NEXT: $exec = S_MOV_B64_term killed [[S_AND_B64_]]
216 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term [[S_XOR_B64_]], implicit $exec
217 ; CHECK-NEXT: [[S_MOV_B64_term1:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term [[S_XOR_B64_]], implicit $exec
218 ; CHECK-NEXT: S_CBRANCH_EXECZ %bb.1, implicit $exec
219 ; CHECK-NEXT: S_BRANCH %bb.2
222 ; CHECK-NEXT: successors: %bb.2(0x80000000)
224 ; CHECK-NEXT: [[COPY3:%[0-9]+]]:sreg_64_xexec = COPY [[S_MOV_B64_term1]]
225 ; CHECK-NEXT: dead [[GLOBAL_LOAD_DWORD:%[0-9]+]]:vgpr_32 = GLOBAL_LOAD_DWORD undef %8:vreg_64, 0, 0, implicit $exec :: (volatile load (s32), addrspace 1)
226 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = COPY [[COPY3]]
229 ; CHECK-NEXT: successors: %bb.3(0x80000000)
231 ; CHECK-NEXT: [[COPY4:%[0-9]+]]:sreg_64_xexec = COPY [[S_MOV_B64_term]]
232 ; CHECK-NEXT: $exec = S_OR_B64_term $exec, killed [[COPY4]], implicit-def $scc
235 ; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
237 ; CHECK-NEXT: S_SLEEP 1
238 ; CHECK-NEXT: [[COPY5:%[0-9]+]]:sreg_64 = COPY $exec, implicit-def $exec
239 ; CHECK-NEXT: [[S_AND_B64_1:%[0-9]+]]:sreg_64 = S_AND_B64 [[COPY5]], [[V_CMP_EQ_U32_e64_]], implicit-def dead $scc
240 ; CHECK-NEXT: [[S_XOR_B64_1:%[0-9]+]]:sreg_64_xexec = S_XOR_B64 [[S_AND_B64_1]], [[COPY5]], implicit-def dead $scc
241 ; CHECK-NEXT: $exec = S_MOV_B64_term killed [[S_AND_B64_1]]
242 ; CHECK-NEXT: [[S_MOV_B64_term:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term [[S_XOR_B64_1]], implicit $exec
243 ; CHECK-NEXT: [[S_MOV_B64_term1:%[0-9]+]]:sreg_64_xexec = S_MOV_B64_term [[S_XOR_B64_1]], implicit $exec
244 ; CHECK-NEXT: S_CBRANCH_EXECZ %bb.1, implicit $exec
245 ; CHECK-NEXT: S_BRANCH %bb.2
247 liveins: $vgpr0, $vgpr1, $sgpr30_sgpr31
249 %0:vgpr_32 = COPY killed $vgpr0
250 %1:vgpr_32 = COPY killed $vgpr1
251 %3:sreg_64_xexec = V_CMP_EQ_U32_e64 killed %0, killed %1, implicit $exec
252 %10:sreg_64_xexec = SI_IF %3, %bb.1, implicit-def $exec, implicit-def dead $scc, implicit $exec
253 %14:sreg_64_xexec = S_MOV_B64_term %10, implicit $exec
254 %13:sreg_64_xexec = S_MOV_B64_term %10, implicit $exec
258 %11:sreg_64_xexec = COPY %13
259 dead %6:vgpr_32 = GLOBAL_LOAD_DWORD undef %8:vreg_64, 0, 0, implicit $exec :: (volatile load (s32), addrspace 1)
260 %14:sreg_64_xexec = COPY %11
263 %12:sreg_64_xexec = COPY %14
264 SI_END_CF killed %12, implicit-def $exec, implicit-def dead $scc, implicit $exec
266 %9:sreg_64_xexec = SI_IF %3, %bb.1, implicit-def $exec, implicit-def dead $scc, implicit $exec
267 %14:sreg_64_xexec = S_MOV_B64_term %9, implicit $exec
268 %13:sreg_64_xexec = S_MOV_B64_term %9, implicit $exec