1 # RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs -run-pass=si-peephole-sdwa -o - %s | FileCheck -check-prefix=GFX9 %s
2 # RUN: llc -march=amdgcn -mcpu=fiji -verify-machineinstrs -run-pass=si-peephole-sdwa -o - %s | FileCheck -check-prefix=GFX9 %s
4 # test for 3 consecutive _sdwa's
5 # GFX9-LABEL: name: test1_add_co_sdwa
6 # GFX9: = nsw V_ADD_CO_U32_sdwa
7 # GFX9-NEXT: = nuw V_ADDC_U32_e64
8 # GFX9: V_ADD_CO_U32_sdwa
9 # GFX9-NEXT: V_ADDC_U32_e64
10 # GFX9: V_ADD_CO_U32_sdwa
11 # GFX9-NEXT: V_ADDC_U32_e64
13 name: test1_add_co_sdwa
14 tracksRegLiveness: true
16 - { id: 0, class: vgpr_32, preferred-register: '' }
18 - { reg: '$vgpr0', virtual-reg: '%0' }
19 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
22 liveins: $vgpr0, $sgpr0_sgpr1
24 %1:sgpr_64 = COPY $sgpr0_sgpr1
25 %0:vgpr_32 = COPY $vgpr0
26 %22:sreg_32_xm0 = S_MOV_B32 255
27 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
28 %30:vreg_64 = COPY $sgpr0_sgpr1
29 %63:vgpr_32, %65:sreg_64_xexec = nsw V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
30 %64:vgpr_32, dead %66:sreg_64_xexec = nuw V_ADDC_U32_e64 %30.sub1, %0, killed %65, 0, implicit $exec
31 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
32 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
34 %161:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
35 %163:vgpr_32, %165:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %161, 0, implicit $exec
36 %164:vgpr_32, dead %166:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %165, 0, implicit $exec
37 %162:vreg_64 = REG_SEQUENCE %163, %subreg.sub0, %164, %subreg.sub1
38 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %162, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
40 %171:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
41 %173:vgpr_32, %175:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %171, 0, implicit $exec
42 %174:vgpr_32, dead %176:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %175, 0, implicit $exec
43 %172:vreg_64 = REG_SEQUENCE %173, %subreg.sub0, %174, %subreg.sub1
44 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %172, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
48 # test for VCC interference on sdwa, should generate 1 xform only
49 # GFX9-LABEL: name: test2_add_co_sdwa
50 # GFX9: V_ADD_CO_U32_sdwa
51 # GFX9: V_ADDC_U32_e64
52 # GFX9-NOT: V_ADD_CO_U32_sdwa
53 # GFX9-NOT: V_ADDC_U32_e32
55 name: test2_add_co_sdwa
56 tracksRegLiveness: true
58 - { id: 0, class: vgpr_32, preferred-register: '' }
60 - { reg: '$vgpr0', virtual-reg: '%0' }
61 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
64 liveins: $vgpr0, $sgpr0_sgpr1
66 %1:sgpr_64 = COPY $sgpr0_sgpr1
67 %0:vgpr_32 = COPY $vgpr0
68 %22:sreg_32_xm0 = S_MOV_B32 255
69 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
70 %30:vreg_64 = COPY $sgpr0_sgpr1
71 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
73 %161:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
74 %163:vgpr_32, %165:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %161, 0, implicit $exec
75 %164:vgpr_32, dead %166:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %165, 0, implicit $exec
76 %162:vreg_64 = REG_SEQUENCE %163, %subreg.sub0, %164, %subreg.sub1
78 %64:vgpr_32, dead %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %65, 0, implicit $exec
79 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
80 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
82 %161:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
83 %163:vgpr_32, %165:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %161, 0, implicit $exec
84 %164:vgpr_32, dead %166:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %165, 0, implicit $exec
85 %162:vreg_64 = REG_SEQUENCE %163, %subreg.sub0, %164, %subreg.sub1
86 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %162, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
90 # test for CarryOut used, should reject
91 # GFX9-LABEL: name: test3_add_co_sdwa
92 # GFX9: V_ADD_CO_U32_e64
93 # GFX9: V_ADDC_U32_e64
94 # GFX9-NOT: V_ADD_CO_U32_sdwa
95 # GFX9-NOT: V_ADDC_U32_e32
97 name: test3_add_co_sdwa
98 tracksRegLiveness: true
100 - { id: 0, class: vgpr_32, preferred-register: '' }
102 - { reg: '$vgpr0', virtual-reg: '%0' }
103 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
106 liveins: $vgpr0, $sgpr0_sgpr1
108 %1:sgpr_64 = COPY $sgpr0_sgpr1
109 %0:vgpr_32 = COPY $vgpr0
110 %22:sreg_32_xm0 = S_MOV_B32 255
111 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
112 %30:vreg_64 = COPY $sgpr0_sgpr1
113 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
114 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, killed %65, 0, implicit $exec
115 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %66, %subreg.sub1
116 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
120 # test for CarryIn used more than once, should reject
121 # GFX9-LABEL: name: test4_add_co_sdwa
122 # GFX9: V_ADD_CO_U32_e64
123 # GFX9: V_ADDC_U32_e64
124 # GFX9-NOT: V_ADD_CO_U32_sdwa
125 # GFX9-NOT: V_ADDC_U32_e32
127 name: test4_add_co_sdwa
128 tracksRegLiveness: true
130 - { id: 0, class: vgpr_32, preferred-register: '' }
132 - { reg: '$vgpr0', virtual-reg: '%0' }
133 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
136 liveins: $vgpr0, $sgpr0_sgpr1
138 %1:sgpr_64 = COPY $sgpr0_sgpr1
139 %0:vgpr_32 = COPY $vgpr0
140 %22:sreg_32_xm0 = S_MOV_B32 255
141 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
142 %30:vreg_64 = COPY $sgpr0_sgpr1
143 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
144 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
145 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %65, %subreg.sub1
146 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
151 # test for simple example, should generate sdwa
152 # GFX9-LABEL: name: test5_add_co_sdwa
153 # GFX9: V_ADD_CO_U32_sdwa
154 # GFX9: V_ADDC_U32_e64
156 name: test5_add_co_sdwa
157 tracksRegLiveness: true
159 - { id: 0, class: vgpr_32, preferred-register: '' }
161 - { reg: '$vgpr0', virtual-reg: '%0' }
162 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
165 liveins: $vgpr0, $sgpr0_sgpr1
167 %1:sgpr_64 = COPY $sgpr0_sgpr1
168 %0:vgpr_32 = COPY $vgpr0
169 %22:sreg_32_xm0 = S_MOV_B32 255
170 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
171 %30:vreg_64 = COPY $sgpr0_sgpr1
172 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
173 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
174 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
175 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
180 # test for V_ADD_CO_U32_e64 only, should reject
181 # GFX9-LABEL: name: test6_add_co_sdwa
182 # GFX9: V_ADD_CO_U32_e64
183 # GFX9-NOT: V_ADD_CO_U32_sdwa
184 # GFX9-NOT: V_ADDC_U32_e32
186 name: test6_add_co_sdwa
187 tracksRegLiveness: true
189 - { id: 0, class: vgpr_32, preferred-register: '' }
191 - { reg: '$vgpr0', virtual-reg: '%0' }
192 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
195 liveins: $vgpr0, $sgpr0_sgpr1
197 %1:sgpr_64 = COPY $sgpr0_sgpr1
198 %0:vgpr_32 = COPY $vgpr0
199 %22:sreg_32_xm0 = S_MOV_B32 255
200 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
201 %30:vreg_64 = COPY $sgpr0_sgpr1
202 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
203 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %23, %subreg.sub1
204 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
209 # test for V_ADDC_U32_e64 only, should reject
210 # GFX9-LABEL: name: test7_add_co_sdwa
211 # GFX9: V_ADDC_U32_e64
212 # GFX9-NOT: V_ADD_CO_U32_sdwa
213 # GFX9-NOT: V_ADDC_U32_e32
215 name: test7_add_co_sdwa
216 tracksRegLiveness: true
218 - { id: 0, class: vgpr_32, preferred-register: '' }
220 - { reg: '$vgpr0', virtual-reg: '%0' }
221 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
224 liveins: $vgpr0, $sgpr0_sgpr1
226 %1:sgpr_64 = COPY $sgpr0_sgpr1
227 %0:vgpr_32 = COPY $vgpr0
228 %22:sreg_32_xm0 = S_MOV_B32 255
229 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
230 %24:sreg_64_xexec = COPY $sgpr0_sgpr1
232 %30:vreg_64 = COPY $sgpr0_sgpr1
233 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %24, 0, implicit $exec
234 %62:vreg_64 = REG_SEQUENCE %23, %subreg.sub0, %23, %subreg.sub1
235 GLOBAL_STORE_DWORDX2_SADDR %30.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
240 # test for $vcc defined between two adds, should not generate
241 # GFX9-LABEL: name: test8_add_co_sdwa
242 # GFX9-NOT: V_ADD_CO_U32_sdwa
243 # GFX9: V_ADDC_U32_e64
245 name: test8_add_co_sdwa
246 tracksRegLiveness: true
248 - { id: 0, class: vgpr_32, preferred-register: '' }
250 - { reg: '$vgpr0', virtual-reg: '%0' }
251 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
254 liveins: $vgpr0, $sgpr0_sgpr1
256 %1:sgpr_64 = COPY $sgpr0_sgpr1
257 %0:vgpr_32 = COPY $vgpr0
258 %22:sreg_32_xm0 = S_MOV_B32 255
259 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
260 %30:vreg_64 = COPY $sgpr0_sgpr1
261 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
263 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
264 %31:vreg_64 = COPY $vcc
265 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
266 GLOBAL_STORE_DWORDX2_SADDR %31.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
271 # test for non dead $vcc, should not generate
272 # GFX9-LABEL: name: test9_add_co_sdwa
273 # GFX9-NOT: V_ADD_CO_U32_sdwa
274 # GFX9: V_ADDC_U32_e64
276 name: test9_add_co_sdwa
277 tracksRegLiveness: true
279 - { id: 0, class: vgpr_32, preferred-register: '' }
281 - { reg: '$vgpr0', virtual-reg: '%0' }
282 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
285 liveins: $vgpr0, $sgpr0_sgpr1
287 %1:sgpr_64 = COPY $sgpr0_sgpr1
288 %0:vgpr_32 = COPY $vgpr0
289 %22:sreg_32_xm0 = S_MOV_B32 255
290 %30:vreg_64 = COPY $sgpr0_sgpr1
292 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
293 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
294 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
295 %31:vreg_64 = COPY $vcc
296 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
297 GLOBAL_STORE_DWORDX2_SADDR %31.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
302 # test for def $vcc_lo, should not generate
303 # GFX9-LABEL: name: test10_add_co_sdwa
304 # GFX9-NOT: V_ADD_CO_U32_sdwa
305 # GFX9: V_ADDC_U32_e64
307 name: test10_add_co_sdwa
308 tracksRegLiveness: true
310 - { id: 0, class: vgpr_32, preferred-register: '' }
312 - { reg: '$vgpr0', virtual-reg: '%0' }
313 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
316 liveins: $vgpr0, $sgpr0_sgpr1
318 %1:sgpr_64 = COPY $sgpr0_sgpr1
319 %0:vgpr_32 = COPY $vgpr0
320 %22:sreg_32_xm0 = S_MOV_B32 255
321 %30:vreg_64 = COPY $sgpr0_sgpr1
322 $vcc_lo = COPY %30.sub0
323 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
324 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
325 %31:vgpr_32 = COPY $vcc_lo
326 %32:vreg_64 = REG_SEQUENCE %31, %subreg.sub0, %23, %subreg.sub1
327 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
328 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
329 GLOBAL_STORE_DWORDX2_SADDR %32.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
333 # test for read $vcc_hi, should not generate
334 # GFX9-LABEL: name: test11_add_co_sdwa
335 # GFX9-NOT: V_ADD_CO_U32_sdwa
336 # GFX9: V_ADDC_U32_e64
338 name: test11_add_co_sdwa
339 tracksRegLiveness: true
341 - { id: 0, class: vgpr_32, preferred-register: '' }
343 - { reg: '$vgpr0', virtual-reg: '%0' }
344 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
347 liveins: $vgpr0, $sgpr0_sgpr1
349 %1:sgpr_64 = COPY $sgpr0_sgpr1
350 %0:vgpr_32 = COPY $vgpr0
351 %22:sreg_32_xm0 = S_MOV_B32 255
352 %30:vreg_64 = COPY $sgpr0_sgpr1
353 $vcc_hi = COPY %30.sub0
354 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
355 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
356 %31:vgpr_32 = COPY $vcc_hi
357 %32:vreg_64 = REG_SEQUENCE %31, %subreg.sub0, %23, %subreg.sub1
358 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
359 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
360 GLOBAL_STORE_DWORDX2_SADDR %32.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))
364 # test for $vcc defined and used between adds, should not generate
365 # GFX9-LABEL: name: test12_add_co_sdwa
366 # GFX9-NOT: V_ADD_CO_U32_sdwa
367 # GFX9: V_ADDC_U32_e64
369 name: test12_add_co_sdwa
370 tracksRegLiveness: true
372 - { id: 0, class: vgpr_32, preferred-register: '' }
374 - { reg: '$vgpr0', virtual-reg: '%0' }
375 - { reg: '$sgpr0_sgpr1', virtual-reg: '%1' }
378 liveins: $vgpr0, $sgpr0_sgpr1
380 %1:sgpr_64 = COPY $sgpr0_sgpr1
381 %0:vgpr_32 = COPY $vgpr0
382 %22:sreg_32_xm0 = S_MOV_B32 255
383 %30:vreg_64 = COPY $sgpr0_sgpr1
384 %23:vgpr_32 = V_AND_B32_e32 %22, %0, implicit $exec
385 %63:vgpr_32, %65:sreg_64_xexec = V_ADD_CO_U32_e64 %30.sub0, %23, 0, implicit $exec
387 %31:vreg_64 = COPY killed $vcc
388 %64:vgpr_32, %66:sreg_64_xexec = V_ADDC_U32_e64 %30.sub1, %0, %65, 0, implicit $exec
389 %62:vreg_64 = REG_SEQUENCE %63, %subreg.sub0, %64, %subreg.sub1
390 GLOBAL_STORE_DWORDX2_SADDR %31.sub0, %62, %1, 0, 0, implicit $exec, implicit $exec :: (store (s64))