1 # RUN: llc -march=amdgcn -run-pass si-fold-operands -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s
3 # GCN-LABEL: name: fold-imm-readfirstlane{{$}}
4 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
6 name: fold-imm-readfirstlane
7 tracksRegLiveness: true
10 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
11 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
14 # GCN-LABEL: name: fold-imm-readfirstlane-readfirstlane{{$}}
15 # GCN: %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
16 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
17 # GCN: %2:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
18 # GCN: %3:sreg_32_xm0 = COPY %1
21 name: fold-imm-readfirstlane-readfirstlane
22 tracksRegLiveness: true
25 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
26 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
28 %3:sreg_32_xm0 = V_READFIRSTLANE_B32 %2, implicit $exec
33 # GCN-LABEL: name: fold-copy-readfirstlane{{$}}
34 # GCN: %0:sreg_32_xm0 = COPY $sgpr10
35 # GCN: %1:vgpr_32 = COPY %0
36 # GCN: %2:sreg_32_xm0 = COPY %0
38 name: fold-copy-readfirstlane
39 tracksRegLiveness: true
43 %0:sreg_32_xm0 = COPY $sgpr10
45 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
49 # GCN-LABEL: name: no-fold-copy-readfirstlane-physreg0{{$}}
50 # GCN: %0:vgpr_32 = COPY $sgpr10
51 # GCN-NEXT: %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
53 name: no-fold-copy-readfirstlane-physreg0
54 tracksRegLiveness: true
58 %0:vgpr_32 = COPY $sgpr10
59 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
63 # GCN-LABEL: name: no-fold-copy-readfirstlane-physreg1{{$}}
64 # GCN: $vgpr0 = COPY $sgpr10
65 # GCN-NEXT: %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
67 name: no-fold-copy-readfirstlane-physreg1
68 tracksRegLiveness: true
73 %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
77 # GCN-LABEL: name: no-fold-imm-readfirstlane-physreg{{$}}
78 # GCN: $vgpr0 = V_MOV_B32_e32 123, implicit $exec
79 # GCN-NEXT: V_READFIRSTLANE_B32 $vgpr0, implicit $exec
82 name: no-fold-imm-readfirstlane-physreg
83 tracksRegLiveness: true
86 $vgpr0 = V_MOV_B32_e32 123, implicit $exec
87 %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
90 # TODO: This could be folded, if the search for exec modifications was
93 # GCN-LABEL: name: fold-imm-readfirstlane-cross-block{{$}}
95 # GCN: V_READFIRSTLANE_B32
97 name: fold-imm-readfirstlane-cross-block
98 tracksRegLiveness: true
101 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
104 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
107 # TODO: This could be folded, if the search for exec modifications was
110 # GCN-LABEL: name: fold-copy-readfirstlane-cross-block{{$}}
112 # GCN: V_READFIRSTLANE_B32
114 name: fold-copy-readfirstlane-cross-block
115 tracksRegLiveness: true
119 %0:sreg_32_xm0 = COPY $sgpr12
120 %1:vgpr_32 = V_MOV_B32_e32 %0, implicit $exec
123 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
126 # GCN-LABEL: name: fold-copy-readfirstlane-cross-block-exec-def{{$}}
128 # GCN: $exec = S_MOV_B64_term
129 # GCN: V_READFIRSTLANE_B32
131 name: fold-copy-readfirstlane-cross-block-exec-def
132 tracksRegLiveness: true
135 liveins: $sgpr10_sgpr11, $sgpr12
136 %0:sreg_32_xm0 = COPY $sgpr12
137 %1:vgpr_32 = V_MOV_B32_e32 %0, implicit $exec
138 $exec = S_MOV_B64_term $sgpr10_sgpr11
141 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
144 # GCN-LABEL: name: fold-copy-readfirstlane-same-block-exec-def{{$}}
146 # GCN-NEXT: %1:vgpr_32 = COPY %0
147 # GCN-NEXT: $exec = S_MOV_B64
148 # GCN-NEXT: V_READFIRSTLANE_B32
150 name: fold-copy-readfirstlane-same-block-exec-def
151 tracksRegLiveness: true
154 liveins: $sgpr10_sgpr11, $sgpr12
155 %0:sreg_32_xm0 = COPY $sgpr12
156 %1:vgpr_32 = COPY %0, implicit $exec
157 $exec = S_MOV_B64 $sgpr10_sgpr11
158 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
162 # GCN-LABEL: name: fold-imm-readfirstlane-cross-block-exec-def{{$}}
164 # GCN: $exec = S_MOV_B64
165 # GCN: V_READFIRSTLANE_B32
168 name: fold-imm-readfirstlane-cross-block-exec-def
169 tracksRegLiveness: true
172 liveins: $sgpr10_sgpr11, $sgpr12_sgpr13
173 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
174 $exec = S_MOV_B64_term $sgpr10_sgpr11
177 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
180 # GCN-LABEL: name: fold-imm-readfirstlane-same-block-exec-def{{$}}
182 # GCN-NEXT: $exec = S_MOV_B64
183 # GCN-NEXT: V_READFIRSTLANE_B32
185 name: fold-imm-readfirstlane-same-block-exec-def
186 tracksRegLiveness: true
189 liveins: $sgpr10_sgpr11
190 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
191 $exec = S_MOV_B64 $sgpr10_sgpr11
192 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
196 # GCN-LABEL: name: fold-sgpr-copy-readfirstlane-same-block-exec-def{{$}}
198 # GCN-NEXT: $exec = S_MOV_B64
199 # GCN-NEXT: V_READFIRSTLANE_B32
201 name: fold-sgpr-copy-readfirstlane-same-block-exec-def
202 tracksRegLiveness: true
205 liveins: $sgpr10_sgpr11, $sgpr12
206 %0:vgpr_32 = COPY $sgpr12
207 $exec = S_MOV_B64 $sgpr10_sgpr11
208 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
211 # GCN-LABEL: name: fold-imm-readfirstlane-user{{$}}
212 # GCN: %3:sreg_32_xm0 = S_MOV_B32 123
214 name: fold-imm-readfirstlane-user
215 tracksRegLiveness: true
218 liveins: $vgpr0, $sgpr0_sgpr1
219 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
220 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
221 %2:sreg_32_xm0 = COPY %1
222 %3:sreg_32_xm0 = COPY %2
223 S_ENDPGM 0, implicit %3
226 # GCN-LABEL: name: fold-imm-readlane{{$}}
227 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
229 name: fold-imm-readlane
230 tracksRegLiveness: true
233 liveins: $vgpr0, $sgpr0_sgpr1
234 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
235 %1:sreg_32_xm0 = V_READLANE_B32 %0, 0, implicit $exec
238 # GCN-LABEL: name: fold-imm-readlane-src1{{$}}
239 # GCN: %0:vgpr_32 = COPY $vgpr0
240 # GCN: V_READLANE_B32 %0, 12, implicit $exec
242 name: fold-imm-readlane-src1
243 tracksRegLiveness: true
247 %0:vgpr_32 = COPY $vgpr0
248 %1:sreg_32_xm0 = S_MOV_B32 12
249 %2:sreg_32_xm0 = V_READLANE_B32 %0, %1, implicit $exec
252 # Constant for subreg0
253 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence0{{$}}
255 # GCN: %0:vgpr_32 = COPY $vgpr0
256 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
257 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
258 # GCN-NEXT: %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0, implicit $exec
259 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 0
261 name: fold-imm-readfirstlane-regsequence0
262 tracksRegLiveness: true
266 %0:vgpr_32 = COPY $vgpr0
267 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
268 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
269 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
270 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
273 # Constant for subreg1
274 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence1{{$}}
275 # GCN: %0:vgpr_32 = COPY $vgpr0
276 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
277 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %1, %subreg.sub0, killed %0, %subreg.sub1
278 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
279 # GCN-NEXT: %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1, implicit $exec
282 name: fold-imm-readfirstlane-regsequence1
283 tracksRegLiveness: true
287 %0:vgpr_32 = COPY $vgpr0
288 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
289 %2:vreg_64 = REG_SEQUENCE %1:vgpr_32, %subreg.sub0, killed %0:vgpr_32, %subreg.sub1
290 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
291 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
294 # Different constant regs for each subreg
295 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence2{{$}}
296 # GCN: %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
297 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
298 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
299 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
300 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 1
302 name: fold-imm-readfirstlane-regsequence2
303 tracksRegLiveness: true
306 %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
307 %1:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
308 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
309 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
310 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
313 # Same constant reg for each subreg, so there are multiple constant uses
314 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence3{{$}}
315 # GCN: %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
316 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
317 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
318 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
319 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 0
321 name: fold-imm-readfirstlane-regsequence3
322 tracksRegLiveness: true
325 %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
326 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
327 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
328 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
329 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
332 # FIXME: This should fold
333 # GCN-LABEL: name: fold-copy-readfirstlane-regsequence0{{$}}
334 # GCN: %0:vgpr_32 = COPY $sgpr10
335 # GCN-NEXT: %1:vgpr_32 = COPY $sgpr11
336 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
337 # GCN-NEXT: %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0, implicit $exec
338 # GCN-NEXT: %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1, implicit $exec
340 name: fold-copy-readfirstlane-regsequence0
341 tracksRegLiveness: true
344 liveins: $sgpr10, $sgpr11
345 %0:vgpr_32 = COPY $sgpr10
346 %1:vgpr_32 = COPY $sgpr11
347 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
348 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
349 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
352 # GCN-LABEL: name: fold-copy-readfirstlane-regsequence1{{$}}
353 # GCN: %0:sreg_32_xm0 = COPY $sgpr10
354 # GCN-NEXT: %1:sreg_32_xm0 = COPY $sgpr11
355 # GCN-NEXT: %2:vgpr_32 = COPY %0
356 # GCN-NEXT: %3:vgpr_32 = COPY %1
357 # GCN-NEXT: %4:vreg_64 = REG_SEQUENCE %2, %subreg.sub0, killed %3, %subreg.sub1
358 # GCN-NEXT: %5:sgpr_32 = V_READFIRSTLANE_B32 %4.sub0, implicit $exec
359 # GCN-NEXT: %6:sgpr_32 = V_READFIRSTLANE_B32 %4.sub1, implicit $exec
361 name: fold-copy-readfirstlane-regsequence1
362 tracksRegLiveness: true
365 liveins: $sgpr10, $sgpr11
366 %0:sreg_32_xm0 = COPY $sgpr10
367 %1:sreg_32_xm0 = COPY $sgpr11
370 %4:vreg_64 = REG_SEQUENCE %2:vgpr_32, %subreg.sub0, killed %3:vgpr_32, %subreg.sub1
371 %5:sgpr_32 = V_READFIRSTLANE_B32 %4.sub0:vreg_64, implicit $exec
372 %6:sgpr_32 = V_READFIRSTLANE_B32 %4.sub1:vreg_64, implicit $exec