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
15 # GCN-LABEL: name: fold-imm-readfirstlane-dbgvalue{{$}}
16 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
17 # GCN: DBG_VALUE %0:vgpr_32, 0, 0
19 name: fold-imm-readfirstlane-dbgvalue
20 tracksRegLiveness: true
23 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
24 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
29 # GCN-LABEL: name: fold-imm-readfirstlane-readfirstlane{{$}}
30 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
31 # GCN: %3:sreg_32_xm0 = COPY %1
34 name: fold-imm-readfirstlane-readfirstlane
35 tracksRegLiveness: true
38 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
39 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
41 %3:sreg_32_xm0 = V_READFIRSTLANE_B32 %2, implicit $exec
46 # GCN-LABEL: name: fold-copy-readfirstlane{{$}}
47 # GCN: %0:sreg_32_xm0 = COPY $sgpr10
48 # GCN: %2:sreg_32_xm0 = COPY %0
50 name: fold-copy-readfirstlane
51 tracksRegLiveness: true
55 %0:sreg_32_xm0 = COPY $sgpr10
57 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
61 # GCN-LABEL: name: no-fold-copy-readfirstlane-physreg0{{$}}
62 # GCN: %0:vgpr_32 = COPY $sgpr10
63 # GCN-NEXT: %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
65 name: no-fold-copy-readfirstlane-physreg0
66 tracksRegLiveness: true
70 %0:vgpr_32 = COPY $sgpr10
71 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
75 # GCN-LABEL: name: no-fold-copy-readfirstlane-physreg1{{$}}
76 # GCN: $vgpr0 = COPY $sgpr10
77 # GCN-NEXT: %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
79 name: no-fold-copy-readfirstlane-physreg1
80 tracksRegLiveness: true
85 %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
89 # GCN-LABEL: name: no-fold-imm-readfirstlane-physreg{{$}}
90 # GCN: $vgpr0 = V_MOV_B32_e32 123, implicit $exec
91 # GCN-NEXT: V_READFIRSTLANE_B32 $vgpr0, implicit $exec
94 name: no-fold-imm-readfirstlane-physreg
95 tracksRegLiveness: true
98 $vgpr0 = V_MOV_B32_e32 123, implicit $exec
99 %0:sreg_32_xm0 = V_READFIRSTLANE_B32 $vgpr0, implicit $exec
102 # TODO: This could be folded, if the search for exec modifications was
105 # GCN-LABEL: name: fold-imm-readfirstlane-cross-block{{$}}
107 # GCN: V_READFIRSTLANE_B32
109 name: fold-imm-readfirstlane-cross-block
110 tracksRegLiveness: true
113 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
116 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
119 # TODO: This could be folded, if the search for exec modifications was
122 # GCN-LABEL: name: fold-copy-readfirstlane-cross-block{{$}}
124 # GCN: V_READFIRSTLANE_B32
126 name: fold-copy-readfirstlane-cross-block
127 tracksRegLiveness: true
131 %0:sreg_32_xm0 = COPY $sgpr12
132 %1:vgpr_32 = V_MOV_B32_e32 %0, implicit $exec
135 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
138 # GCN-LABEL: name: fold-copy-readfirstlane-cross-block-exec-def{{$}}
140 # GCN: $exec = S_MOV_B64_term
141 # GCN: V_READFIRSTLANE_B32
143 name: fold-copy-readfirstlane-cross-block-exec-def
144 tracksRegLiveness: true
147 liveins: $sgpr10_sgpr11, $sgpr12
148 %0:sreg_32_xm0 = COPY $sgpr12
149 %1:vgpr_32 = V_MOV_B32_e32 %0, implicit $exec
150 $exec = S_MOV_B64_term $sgpr10_sgpr11
153 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
156 # GCN-LABEL: name: fold-copy-readfirstlane-same-block-exec-def{{$}}
158 # GCN-NEXT: %1:vgpr_32 = COPY %0
159 # GCN-NEXT: $exec = S_MOV_B64
160 # GCN-NEXT: V_READFIRSTLANE_B32
162 name: fold-copy-readfirstlane-same-block-exec-def
163 tracksRegLiveness: true
166 liveins: $sgpr10_sgpr11, $sgpr12
167 %0:sreg_32_xm0 = COPY $sgpr12
168 %1:vgpr_32 = COPY %0, implicit $exec
169 $exec = S_MOV_B64 $sgpr10_sgpr11
170 %2:sreg_32_xm0 = V_READFIRSTLANE_B32 %1, implicit $exec
174 # GCN-LABEL: name: fold-imm-readfirstlane-cross-block-exec-def{{$}}
176 # GCN: $exec = S_MOV_B64
177 # GCN: V_READFIRSTLANE_B32
180 name: fold-imm-readfirstlane-cross-block-exec-def
181 tracksRegLiveness: true
184 liveins: $sgpr10_sgpr11, $sgpr12_sgpr13
185 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
186 $exec = S_MOV_B64_term $sgpr10_sgpr11
189 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
192 # GCN-LABEL: name: fold-imm-readfirstlane-same-block-exec-def{{$}}
194 # GCN-NEXT: $exec = S_MOV_B64
195 # GCN-NEXT: V_READFIRSTLANE_B32
197 name: fold-imm-readfirstlane-same-block-exec-def
198 tracksRegLiveness: true
201 liveins: $sgpr10_sgpr11
202 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
203 $exec = S_MOV_B64 $sgpr10_sgpr11
204 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
208 # GCN-LABEL: name: fold-sgpr-copy-readfirstlane-same-block-exec-def{{$}}
210 # GCN-NEXT: $exec = S_MOV_B64
211 # GCN-NEXT: V_READFIRSTLANE_B32
213 name: fold-sgpr-copy-readfirstlane-same-block-exec-def
214 tracksRegLiveness: true
217 liveins: $sgpr10_sgpr11, $sgpr12
218 %0:vgpr_32 = COPY $sgpr12
219 $exec = S_MOV_B64 $sgpr10_sgpr11
220 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
223 # GCN-LABEL: name: fold-imm-readfirstlane-user{{$}}
224 # GCN: %3:sreg_32_xm0 = S_MOV_B32 123
226 name: fold-imm-readfirstlane-user
227 tracksRegLiveness: true
230 liveins: $vgpr0, $sgpr0_sgpr1
231 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
232 %1:sreg_32_xm0 = V_READFIRSTLANE_B32 %0, implicit $exec
233 %2:sreg_32_xm0 = COPY %1
234 %3:sreg_32_xm0 = COPY %2
235 S_ENDPGM 0, implicit %3
238 # GCN-LABEL: name: fold-imm-readlane{{$}}
239 # GCN: %1:sreg_32_xm0 = S_MOV_B32 123
241 name: fold-imm-readlane
242 tracksRegLiveness: true
245 liveins: $vgpr0, $sgpr0_sgpr1
246 %0:vgpr_32 = V_MOV_B32_e32 123, implicit $exec
247 %1:sreg_32_xm0 = V_READLANE_B32 %0, 0, implicit $exec
251 # GCN-LABEL: name: fold-imm-readlane-src1{{$}}
252 # GCN: %0:vgpr_32 = COPY $vgpr0
253 # GCN: V_READLANE_B32 %0, 12, implicit $exec
255 name: fold-imm-readlane-src1
256 tracksRegLiveness: true
260 %0:vgpr_32 = COPY $vgpr0
261 %1:sreg_32_xm0 = S_MOV_B32 12
262 %2:sreg_32_xm0 = V_READLANE_B32 %0, %1, implicit $exec
265 # Constant for subreg0
266 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence0{{$}}
268 # GCN: %0:vgpr_32 = COPY $vgpr0
269 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
270 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
271 # GCN-NEXT: %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0, implicit $exec
272 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 0
274 name: fold-imm-readfirstlane-regsequence0
275 tracksRegLiveness: true
279 %0:vgpr_32 = COPY $vgpr0
280 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
281 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
282 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
283 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
284 S_NOP 0, implicit %3, implicit %4
287 # Constant for subreg1
288 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence1{{$}}
289 # GCN: %0:vgpr_32 = COPY $vgpr0
290 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
291 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %1, %subreg.sub0, killed %0, %subreg.sub1
292 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
293 # GCN-NEXT: %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1, implicit $exec
296 name: fold-imm-readfirstlane-regsequence1
297 tracksRegLiveness: true
301 %0:vgpr_32 = COPY $vgpr0
302 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
303 %2:vreg_64 = REG_SEQUENCE %1:vgpr_32, %subreg.sub0, killed %0:vgpr_32, %subreg.sub1
304 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
305 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
306 S_NOP 0, implicit %3, implicit %4
309 # Different constant regs for each subreg
310 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence2{{$}}
311 # GCN: %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
312 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
313 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
314 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
315 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 1
317 name: fold-imm-readfirstlane-regsequence2
318 tracksRegLiveness: true
321 %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
322 %1:vgpr_32 = V_MOV_B32_e32 1, implicit $exec
323 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
324 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
325 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
326 S_NOP 0, implicit %3, implicit %4
329 # Same constant reg for each subreg, so there are multiple constant uses
330 # GCN-LABEL: name: fold-imm-readfirstlane-regsequence3{{$}}
331 # GCN: %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
332 # GCN-NEXT: %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
333 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
334 # GCN-NEXT: %3:sgpr_32 = S_MOV_B32 0
335 # GCN-NEXT: %4:sgpr_32 = S_MOV_B32 0
337 name: fold-imm-readfirstlane-regsequence3
338 tracksRegLiveness: true
341 %0:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
342 %1:vgpr_32 = V_MOV_B32_e32 0, implicit $exec
343 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
344 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
345 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
346 S_NOP 0, implicit %3, implicit %4
349 # FIXME: This should fold
350 # GCN-LABEL: name: fold-copy-readfirstlane-regsequence0{{$}}
351 # GCN: %0:vgpr_32 = COPY $sgpr10
352 # GCN-NEXT: %1:vgpr_32 = COPY $sgpr11
353 # GCN-NEXT: %2:vreg_64 = REG_SEQUENCE %0, %subreg.sub0, killed %1, %subreg.sub1
354 # GCN-NEXT: %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0, implicit $exec
355 # GCN-NEXT: %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1, implicit $exec
357 name: fold-copy-readfirstlane-regsequence0
358 tracksRegLiveness: true
361 liveins: $sgpr10, $sgpr11
362 %0:vgpr_32 = COPY $sgpr10
363 %1:vgpr_32 = COPY $sgpr11
364 %2:vreg_64 = REG_SEQUENCE %0:vgpr_32, %subreg.sub0, killed %1:vgpr_32, %subreg.sub1
365 %3:sgpr_32 = V_READFIRSTLANE_B32 %2.sub0:vreg_64, implicit $exec
366 %4:sgpr_32 = V_READFIRSTLANE_B32 %2.sub1:vreg_64, implicit $exec
369 # GCN-LABEL: name: fold-copy-readfirstlane-regsequence1{{$}}
370 # GCN: %0:sreg_32_xm0 = COPY $sgpr10
371 # GCN-NEXT: %1:sreg_32_xm0 = COPY $sgpr11
372 # GCN-NEXT: %2:vgpr_32 = COPY %0
373 # GCN-NEXT: %3:vgpr_32 = COPY %1
374 # GCN-NEXT: %4:vreg_64 = REG_SEQUENCE %2, %subreg.sub0, killed %3, %subreg.sub1
375 # GCN-NEXT: %5:sgpr_32 = V_READFIRSTLANE_B32 %4.sub0, implicit $exec
376 # GCN-NEXT: %6:sgpr_32 = V_READFIRSTLANE_B32 %4.sub1, implicit $exec
378 name: fold-copy-readfirstlane-regsequence1
379 tracksRegLiveness: true
382 liveins: $sgpr10, $sgpr11
383 %0:sreg_32_xm0 = COPY $sgpr10
384 %1:sreg_32_xm0 = COPY $sgpr11
387 %4:vreg_64 = REG_SEQUENCE %2:vgpr_32, %subreg.sub0, killed %3:vgpr_32, %subreg.sub1
388 %5:sgpr_32 = V_READFIRSTLANE_B32 %4.sub0:vreg_64, implicit $exec
389 %6:sgpr_32 = V_READFIRSTLANE_B32 %4.sub1:vreg_64, implicit $exec