1 # RUN: llc -march=amdgcn -run-pass=si-fix-sgpr-copies -verify-machineinstrs -o - %s | FileCheck --check-prefix=GCN %s
3 # GCN-LABEL: name: fix-sgpr-copies
4 # GCN: V_ADD_CO_U32_e32
10 %0:vgpr_32 = IMPLICIT_DEF
11 %1:sreg_32 = IMPLICIT_DEF
12 %2:sreg_32 = IMPLICIT_DEF
13 %3:sreg_32 = IMPLICIT_DEF
14 %4:vgpr_32 = V_CVT_U32_F32_e64 0, %0:vgpr_32, 0, 0, implicit $mode, implicit $exec
15 %5:sreg_32 = COPY %4:vgpr_32
16 %6:sreg_32 = S_ADD_I32 %2:sreg_32, %5:sreg_32, implicit-def $scc
17 %7:sreg_32 = S_ADDC_U32 %3:sreg_32, %1:sreg_32, implicit-def $scc, implicit $scc
20 # Test to ensure i1 phi copies from scalar registers through another phi won't
21 # be promoted into vector ones.
22 # GCN-LABEL: name: fix-sgpr-i1-phi-copies
24 # GCN-NOT: vreg_64 = PHI
26 name: fix-sgpr-i1-phi-copies
27 tracksRegLiveness: true
33 S_CBRANCH_SCC1 %bb.6, implicit undef $scc
36 %3:vreg_1 = IMPLICIT_DEF
39 %4:vreg_1 = PHI %2:sreg_64, %bb.4, %3:vreg_1, %bb.5
42 %5:vreg_1 = PHI %2:sreg_64, %bb.3, %4:vreg_1, %bb.6
46 S_CBRANCH_SCC1 %bb.2, implicit undef $scc
49 %0:sreg_64 = S_MOV_B64 0
53 %1:sreg_64 = S_MOV_B64 -1
57 %2:sreg_64 = PHI %0:sreg_64, %bb.1, %1:sreg_64, %bb.2
58 S_CBRANCH_SCC1 %bb.7, implicit undef $scc
64 # Avoid infinite loop in SIInstrInfo::legalizeGenericOperand when checking for ImpDef.
65 # GCN-LABEL: name: legalize-operand-search-each-def-once
66 # GCN-NOT: sreg_64 PHI
68 name: legalize-operand-search-each-def-once
69 tracksRegLiveness: true
72 successors: %bb.1, %bb.2
75 %0:sgpr_64 = COPY $sgpr0_sgpr1
76 S_CBRANCH_VCCZ %bb.2, implicit undef $vcc
80 %1:vreg_64 = IMPLICIT_DEF
84 %2:sgpr_64 = PHI %0, %bb.0, %1, %bb.1
85 $sgpr0_sgpr1 = COPY %0
88 # A REG_SEQUENCE that uses registers defined by both a PHI and a COPY could
89 # result in an endless search.
90 # GCN-LABEL: name: process-phi-search-each-use-once
91 # GCN-NOT: sreg_32 PHI
93 name: process-phi-search-each-use-once
94 tracksRegLiveness: true
97 successors: %bb.1, %bb.2
100 %0:vgpr_32 = COPY $vgpr3
101 S_CBRANCH_VCCZ %bb.2, implicit undef $vcc
105 %1:sgpr_32 = IMPLICIT_DEF
109 %2:sgpr_32 = PHI %0, %bb.0, %1, %bb.1
110 %3:vreg_64 = REG_SEQUENCE %2, %subreg.sub0, %0, %subreg.sub1
111 $vgpr3 = COPY %3.sub0
114 # Test to ensure that undef SCC gets properly propagated.
115 # GCN-LABEL: name: scc_undef
116 # GCN: S_CSELECT_B64 -1, 0, implicit undef $scc
120 tracksRegLiveness: true
124 %1:vgpr_32 = IMPLICIT_DEF
125 %2:sreg_32 = S_MOV_B32 1
126 %3:sreg_32 = COPY %1:vgpr_32
127 %4:sreg_32 = S_CSELECT_B32 killed %2:sreg_32, killed %3:sreg_32, implicit undef $scc
131 # Test that the VGPR immediate is replaced with an SGPR one.
132 # GCN-LABEL: name: reg_sequence_vgpr_immediate
133 # GCN: [[A_SGPR:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
134 # GCN-NEXT: [[VGPR_CONST:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 37
135 # GCN-NEXT: [[SGPR_CONST:%[0-9]+]]:sgpr_32 = S_MOV_B32 37
136 # GCN-NEXT: {{%[0-9]+}}:sreg_64 = REG_SEQUENCE [[SGPR_CONST]], %subreg.sub0, [[A_SGPR]], %subreg.sub1
137 name: reg_sequence_vgpr_immediate
140 %0:sreg_32 = IMPLICIT_DEF
141 %1:vgpr_32 = V_MOV_B32_e32 37, implicit $exec
142 %2:sreg_64 = REG_SEQUENCE %1:vgpr_32, %subreg.sub0, %0:sreg_32, %subreg.sub1
144 %3:vgpr_32 = V_ADD_U32_e32 %1:vgpr_32, %1:vgpr_32, implicit $exec
148 # GCN-LABEL: name: insert_subreg_vgpr_immediate
149 # GCN: [[DST:%[0-9]+]]:sgpr_128 = REG_SEQUENCE $sgpr0, %subreg.sub0, $sgpr0, %subreg.sub2
150 # GCN-NEXT: [[SGPR_CONST:%[0-9]+]]:sgpr_32 = S_MOV_B32 43
151 # GCN-NEXT: {{%[0-9]+}}:sgpr_128 = INSERT_SUBREG [[DST]], [[SGPR_CONST]], %subreg.sub3
152 name: insert_subreg_vgpr_immediate
155 %0:sgpr_128 = REG_SEQUENCE $sgpr0, %subreg.sub0, $sgpr0, %subreg.sub2
156 %1:vgpr_32 = V_MOV_B32_e32 43, implicit $exec
157 %2:sgpr_128 = INSERT_SUBREG %0, %1, %subreg.sub3
161 # GCN-LABEL: name: phi_vgpr_immediate
163 # GCN: [[SGPR:%[0-9]+]]:sgpr_32 = S_MOV_B32 51
167 # GCN: sreg_32 = PHI [[SGPR]], %bb.1
168 name: phi_vgpr_immediate
169 tracksRegLiveness: true
172 S_CBRANCH_SCC1 %bb.2, implicit undef $scc
175 %0:vgpr_32 = V_MOV_B32_e32 51, implicit $exec
179 %1:sreg_32 = IMPLICIT_DEF
183 %2:sreg_32 = PHI %0:vgpr_32, %bb.1, %1:sreg_32, %bb.2
189 ; GCN-LABEL: name: cmp_f32
190 ; GCN: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
191 ; GCN-NEXT: [[DEF1:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
192 ; GCN-NEXT: [[V_CVT_F32_U32_e64_:%[0-9]+]]:vgpr_32 = V_CVT_F32_U32_e64 [[DEF]], 0, 0, implicit $mode, implicit $exec
193 ; GCN-NEXT: [[DEF2:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
194 ; GCN-NEXT: %6:sreg_64_xexec = nofpexcept V_CMP_LT_F32_e64 0, [[V_CVT_F32_U32_e64_]], 0, [[DEF1]], 0, implicit $mode, implicit $exec
195 ; GCN-NEXT: [[V_CNDMASK_B32_e64_:%[0-9]+]]:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, -1, killed %6, implicit $exec
196 %0:vgpr_32 = IMPLICIT_DEF
197 %1:sreg_32 = IMPLICIT_DEF
198 %2:vgpr_32 = V_CVT_F32_U32_e64 %0:vgpr_32, 0, 0, implicit $mode, implicit $exec
199 %3:sreg_32 = COPY %2:vgpr_32
200 nofpexcept S_CMP_LT_F32 killed %3:sreg_32, %1:sreg_32, implicit-def $scc, implicit $mode
201 %4:sreg_64_xexec = COPY $scc
202 %5:vgpr_32 = V_CNDMASK_B32_e64 0, 0, 0, -1, killed %4, implicit $exec
205 # Test to ensure that src2 of fmac is moved to vgpr
210 ; GCN-LABEL: name: fmac_f32
211 ; GCN: [[DEF:%[0-9]+]]:vgpr_32 = IMPLICIT_DEF
212 ; GCN-NEXT: [[DEF1:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
213 ; GCN-NEXT: [[DEF2:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
214 ; GCN-NEXT: [[V_CVT_F32_U32_e64_:%[0-9]+]]:vgpr_32 = V_CVT_F32_U32_e64 [[DEF]], 0, 0, implicit $mode, implicit $exec
215 ; GCN-NEXT: [[DEF3:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
216 ; GCN-NEXT: [[COPY:%[0-9]+]]:vgpr_32 = COPY [[DEF2]]
217 ; GCN-NEXT: %6:vgpr_32 = nofpexcept V_FMAC_F32_e64 0, [[V_CVT_F32_U32_e64_]], 0, [[DEF1]], 0, [[COPY]], 0, 0, implicit $mode, implicit $exec
218 %0:vgpr_32 = IMPLICIT_DEF
219 %1:sreg_32 = IMPLICIT_DEF
220 %2:sreg_32 = IMPLICIT_DEF
221 %3:vgpr_32 = V_CVT_F32_U32_e64 %0:vgpr_32, 0, 0, implicit $mode, implicit $exec
222 %4:sreg_32 = COPY %3:vgpr_32
223 %5:sreg_32 = nofpexcept S_FMAC_F32 killed %4:sreg_32, %1:sreg_32, %2:sreg_32, implicit $mode
227 # GCN-LABEL: name: moveimm_subreg_input
228 # GCN: %0:vreg_64 = V_MOV_B64_PSEUDO 0, implicit $exec
229 # GCN: :vgpr_32 = COPY %0.sub0
230 name: moveimm_subreg_input
233 %0:vreg_64 = V_MOV_B64_PSEUDO 0, implicit $exec
234 %1:sreg_32 = COPY %0.sub0