1 # RUN: llc -mtriple=amdgcn -amdgpu-enable-merge-m0 -verify-machineinstrs -run-pass si-fix-sgpr-copies %s -o - | FileCheck -check-prefix=GCN %s
3 # GCN-LABEL: name: merge-m0-many-init
6 # GCN-NEXT: IMPLICIT_DEF
7 # GCN-NEXT: IMPLICIT_DEF
8 # GCN-NEXT: DS_WRITE_B32
9 # GCN-NEXT: DS_WRITE_B32
10 # GCN-NEXT: SI_INIT_M0 65536
11 # GCN-NEXT: DS_WRITE_B32
12 # GCN-NEXT: DS_WRITE_B32
13 # GCN-NEXT: SI_INIT_M0 -1
14 # GCN-NEXT: DS_WRITE_B32
15 # GCN-NEXT: SI_INIT_M0 65536
16 # GCN-NEXT: DS_WRITE_B32
20 # GCN-NEXT: DS_WRITE_B32
21 # GCN-NEXT: DS_WRITE_B32
24 # GCN: SI_INIT_M0 65536
25 # GCN-NEXT: DS_WRITE_B32
33 # GCN-NEXT: SI_INIT_M0 4
34 # GCN-NEXT: DS_WRITE_B32
39 # GCN-NEXT: SI_INIT_M0 4
40 # GCN-NEXT: DS_WRITE_B32
44 # GCN-NEXT: DS_WRITE_B32
46 # GCN-NEXT: DS_WRITE_B32
47 # GCN-NEXT: SI_INIT_M0 %2
48 # GCN-NEXT: DS_WRITE_B32
49 # GCN-NEXT: SI_INIT_M0 -1
50 # GCN-NEXT: DS_WRITE_B32
52 name: merge-m0-many-init
54 - { id: 0, class: vgpr_32 }
55 - { id: 1, class: vgpr_32 }
56 - { id: 2, class: sreg_32_xm0 }
59 successors: %bb.1, %bb.2
63 SI_INIT_M0 -1, implicit-def $m0
64 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
65 SI_INIT_M0 -1, implicit-def $m0
66 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
67 SI_INIT_M0 65536, implicit-def $m0
68 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
69 SI_INIT_M0 65536, implicit-def $m0
70 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
71 SI_INIT_M0 -1, implicit-def $m0
72 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
73 SI_INIT_M0 65536, implicit-def $m0
74 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
75 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
80 SI_INIT_M0 -1, implicit-def $m0
81 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
82 SI_INIT_M0 -1, implicit-def $m0
83 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
88 SI_INIT_M0 65536, implicit-def $m0
89 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
93 successors: %bb.4, %bb.5
94 S_CBRANCH_VCCZ %bb.4, implicit undef $vcc
99 SI_INIT_M0 3, implicit-def $m0
100 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
101 SI_INIT_M0 4, implicit-def $m0
102 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
107 SI_INIT_M0 3, implicit-def $m0
108 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
109 SI_INIT_M0 4, implicit-def $m0
110 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
114 successors: %bb.0.entry, %bb.6
115 SI_INIT_M0 -1, implicit-def $m0
116 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
118 SI_INIT_M0 %2, implicit-def $m0
119 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
120 SI_INIT_M0 %2, implicit-def $m0
121 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
122 SI_INIT_M0 -1, implicit-def $m0
123 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
124 S_CBRANCH_VCCZ %bb.6, implicit undef $vcc
129 # GCN-LABEL: name: merge-m0-dont-hoist-past-init-with-different-initializer
131 # GCN: SI_INIT_M0 65536
132 # GCN-NEXT: IMPLICIT_DEF
133 # GCN-NEXT: IMPLICIT_DEF
134 # GCN-NEXT: DS_WRITE_B32
137 # GCN-NOT: SI_INIT_M0 65536
138 # GCN-NOT: SI_INIT_M0 -1
146 name: merge-m0-dont-hoist-past-init-with-different-initializer
148 - { id: 0, class: vgpr_32 }
149 - { id: 1, class: vgpr_32 }
156 SI_INIT_M0 65536, implicit-def $m0
157 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
161 successors: %bb.2, %bb.3
163 SI_INIT_M0 65536, implicit-def $m0
164 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
165 S_CBRANCH_VCCZ %bb.2, implicit undef $vcc
171 SI_INIT_M0 -1, implicit-def $m0
172 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
178 SI_INIT_M0 -1, implicit-def $m0
179 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
186 # GCN-LABEL: name: merge-m0-after-prologue
188 # GCN-NOT: SI_INIT_M0
190 # GCN-NEXT: SI_INIT_M0
193 # GCN-NOT: SI_INIT_M0 -1
196 # GCN-NOT: SI_INIT_MO -1
198 name: merge-m0-after-prologue
200 - { id: 0, class: vgpr_32 }
201 - { id: 1, class: vgpr_32 }
204 successors: %bb.1, %bb.2
205 liveins: $sgpr0_sgpr1
207 $exec = S_OR_B64 $exec, killed $sgpr0_sgpr1, implicit-def $scc
210 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
216 SI_INIT_M0 -1, implicit-def $m0
217 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
223 SI_INIT_M0 -1, implicit-def $m0
224 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
231 # GCN-LABEL: name: move-m0-avoid-hazard
232 # GCN: $m0 = S_MOV_B32 -1
233 # GCN-NEXT: $vgpr0 = V_MOV_B32_e32 0, implicit $exec
234 # GCN-NEXT: DS_GWS_INIT $vgpr0, 0, implicit $m0, implicit $exec
236 name: move-m0-avoid-hazard
239 $vgpr0 = V_MOV_B32_e32 0, implicit $exec
241 DS_GWS_INIT $vgpr0, 0, implicit $m0, implicit $exec
244 # GCN-LABEL: name: move-m0-with-prologue
245 # GCN: $exec = S_OR_B64 $exec, killed $sgpr0_sgpr1, implicit-def $scc
246 # GCN: $m0 = S_MOV_B32 -1
247 # GCN-NEXT: $vgpr0 = V_MOV_B32_e32 0, implicit $exec
248 # GCN-NEXT: DS_GWS_INIT $vgpr0, 0, implicit $m0, implicit $exec
250 name: move-m0-with-prologue
253 liveins: $sgpr0_sgpr1
255 $exec = S_OR_B64 $exec, killed $sgpr0_sgpr1, implicit-def $scc
256 $vgpr0 = V_MOV_B32_e32 0, implicit $exec
258 DS_GWS_INIT $vgpr0, 0, implicit $m0, implicit $exec
261 # GCN-LABEL: name: move-m0-different-initializer
263 # GCN-NEXT: %0:vgpr_32 = IMPLICIT_DEF
264 # GCN: SI_INIT_M0 65536
267 name: move-m0-different-initializer
269 - { id: 0, class: vgpr_32 }
270 - { id: 1, class: vgpr_32 }
275 SI_INIT_M0 -1, implicit-def $m0
276 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
278 SI_INIT_M0 65536, implicit-def $m0
279 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
282 # GCN-LABEL: name: move-m0-schedule-boundary
284 # GCN-NEXT: SI_INIT_M0 -1
286 name: move-m0-schedule-boundary
288 - { id: 0, class: vgpr_32 }
289 - { id: 1, class: vgpr_32 }
294 S_SETREG_IMM32_B32 0, 1, implicit-def $mode, implicit $mode
295 SI_INIT_M0 -1, implicit-def $m0
296 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
300 # GCN-LABEL: name: m0-in-loop-0
303 # GCN-NEXT: IMPLICIT_DEF
304 # GCN-NEXT: IMPLICIT_DEF
305 # GCN-NEXT: IMPLICIT_DEF
306 # GCN-NEXT: DS_WRITE_B32
310 # GCN-NEXT: DS_WRITE_B32
311 # GCN-NEXT: $m0 = COPY %2
316 - { id: 0, class: vgpr_32 }
317 - { id: 1, class: vgpr_32 }
318 - { id: 2, class: sgpr_32 }
326 SI_INIT_M0 -1, implicit-def $m0
327 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
331 successors: %bb.1, %bb.2
333 SI_INIT_M0 -1, implicit-def $m0
334 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
335 $m0 = COPY %2:sgpr_32
336 S_SENDMSG 34, implicit $exec, implicit $m0
337 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
344 # GCN-LABEL: name: m0-in-loop-1
347 # GCN-NEXT: IMPLICIT_DEF
348 # GCN-NEXT: IMPLICIT_DEF
349 # GCN-NEXT: IMPLICIT_DEF
350 # GCN-NEXT: DS_WRITE_B32
353 # GCN-NOT: SI_INIT_M0 -1
359 - { id: 0, class: vgpr_32 }
360 - { id: 1, class: vgpr_32 }
361 - { id: 2, class: sgpr_32 }
369 SI_INIT_M0 -1, implicit-def $m0
370 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
374 successors: %bb.1, %bb.2
376 SI_INIT_M0 -1, implicit-def $m0
377 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
378 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
385 # GCN-LABEL: name: m0-in-loop-2
388 # GCN-NEXT: IMPLICIT_DEF
389 # GCN-NEXT: IMPLICIT_DEF
390 # GCN-NEXT: IMPLICIT_DEF
391 # GCN-NEXT: DS_WRITE_B32
396 # GCN-NEXT: SI_INIT_M0 -1
397 # GCN-NEXT: DS_WRITE_B32
402 - { id: 0, class: vgpr_32 }
403 - { id: 1, class: vgpr_32 }
404 - { id: 2, class: sgpr_32 }
412 SI_INIT_M0 -1, implicit-def $m0
413 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
417 successors: %bb.1, %bb.2
419 $m0 = COPY %2:sgpr_32
420 S_SENDMSG 34, implicit $exec, implicit $m0
421 SI_INIT_M0 -1, implicit-def $m0
422 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
423 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
430 # GCN-LABEL: name: m0-in-loop-3
433 # GCN-NEXT: IMPLICIT_DEF
434 # GCN-NEXT: IMPLICIT_DEF
435 # GCN-NEXT: IMPLICIT_DEF
436 # GCN-NEXT: DS_WRITE_B32
441 # GCN-NEXT: SI_INIT_M0 -1
442 # GCN-NEXT: DS_WRITE_B32
443 # GCN-NEXT: DS_WRITE_B32
448 - { id: 0, class: vgpr_32 }
449 - { id: 1, class: vgpr_32 }
450 - { id: 2, class: sgpr_32 }
458 SI_INIT_M0 -1, implicit-def $m0
459 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
463 successors: %bb.1, %bb.2
465 $m0 = COPY %2:sgpr_32
466 S_SENDMSG 34, implicit $exec, implicit $m0
467 SI_INIT_M0 -1, implicit-def $m0
468 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
469 SI_INIT_M0 -1, implicit-def $m0
470 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
471 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
478 # GCN-LABEL: name: m0-in-loop-4
481 # GCN-NEXT: IMPLICIT_DEF
482 # GCN-NEXT: IMPLICIT_DEF
483 # GCN-NEXT: IMPLICIT_DEF
484 # GCN-NEXT: DS_WRITE_B32
488 # GCN-NEXT: DS_WRITE_B32
489 # GCN-NEXT: DS_WRITE_B32
490 # GCN-NEXT: $m0 = COPY %2
496 - { id: 0, class: vgpr_32 }
497 - { id: 1, class: vgpr_32 }
498 - { id: 2, class: sgpr_32 }
506 SI_INIT_M0 -1, implicit-def $m0
507 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
511 successors: %bb.1, %bb.2
513 SI_INIT_M0 -1, implicit-def $m0
514 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
515 SI_INIT_M0 -1, implicit-def $m0
516 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
517 $m0 = COPY %2:sgpr_32
518 S_SENDMSG 34, implicit $exec, implicit $m0
519 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
526 # GCN-LABEL: name: m0-in-loop-5
529 # GCN-NEXT: IMPLICIT_DEF
530 # GCN-NEXT: IMPLICIT_DEF
531 # GCN-NEXT: IMPLICIT_DEF
532 # GCN-NEXT: DS_WRITE_B32
535 # GCN: SI_INIT_M0 65536
536 # GCN-NEXT: DS_WRITE_B32
537 # GCN-NEXT: SI_INIT_M0 -1
538 # GCN-NEXT: DS_WRITE_B32
539 # GCN-NEXT: $m0 = COPY %2
545 - { id: 0, class: vgpr_32 }
546 - { id: 1, class: vgpr_32 }
547 - { id: 2, class: sgpr_32 }
555 SI_INIT_M0 -1, implicit-def $m0
556 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
560 successors: %bb.1, %bb.2
562 SI_INIT_M0 65536, implicit-def $m0
563 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
564 SI_INIT_M0 -1, implicit-def $m0
565 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
566 $m0 = COPY %2:sgpr_32
567 S_SENDMSG 34, implicit $exec, implicit $m0
568 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
575 # GCN-LABEL: name: m0-in-loop-6
578 # GCN-NEXT: IMPLICIT_DEF
579 # GCN-NEXT: IMPLICIT_DEF
580 # GCN-NEXT: IMPLICIT_DEF
581 # GCN-NEXT: DS_WRITE_B32
585 # GCN-NEXT: DS_WRITE_B32
586 # GCN-NEXT: DS_WRITE_B32
587 # GCN-NEXT: $m0 = COPY %2
593 - { id: 0, class: vgpr_32 }
594 - { id: 1, class: vgpr_32 }
595 - { id: 2, class: sgpr_32 }
603 SI_INIT_M0 -1, implicit-def $m0
604 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
610 SI_INIT_M0 -1, implicit-def $m0
611 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
612 SI_INIT_M0 -1, implicit-def $m0
613 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
614 $m0 = COPY %2:sgpr_32
615 S_SENDMSG 34, implicit $exec, implicit $m0
619 successors: %bb.3, %bb.1
620 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc
628 # GCN-LABEL: name: m0-in-loop-7
631 # GCN-NEXT: IMPLICIT_DEF
632 # GCN-NEXT: IMPLICIT_DEF
633 # GCN-NEXT: IMPLICIT_DEF
634 # GCN-NEXT: DS_WRITE_B32
638 # GCN-NEXT: DS_WRITE_B32
639 # GCN-NEXT: DS_WRITE_B32
648 - { id: 0, class: vgpr_32 }
649 - { id: 1, class: vgpr_32 }
650 - { id: 2, class: sgpr_32 }
658 SI_INIT_M0 -1, implicit-def $m0
659 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
665 SI_INIT_M0 -1, implicit-def $m0
666 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
667 SI_INIT_M0 -1, implicit-def $m0
668 DS_WRITE_B32 %0, %1, 0, 0, implicit $m0, implicit $exec
672 successors: %bb.3, %bb.1
673 $m0 = COPY %2:sgpr_32
674 S_SENDMSG 34, implicit $exec, implicit $m0
675 S_CBRANCH_VCCZ %bb.1, implicit undef $vcc