1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64 -aarch64-neon-syntax=generic | FileCheck %s -check-prefixes=CHECK,SDAG
3 ; RUN: llc < %s -global-isel=1 -global-isel-abort=2 -mtriple=aarch64 -aarch64-neon-syntax=generic 2>&1 | FileCheck %s --check-prefixes=CHECK,GISEL
5 ; Function Attrs: nounwind readnone
6 declare i8 @llvm.vector.reduce.add.v2i8(<2 x i8>)
7 declare i8 @llvm.vector.reduce.add.v3i8(<3 x i8>)
8 declare i8 @llvm.vector.reduce.add.v4i8(<4 x i8>)
9 declare i8 @llvm.vector.reduce.add.v8i8(<8 x i8>)
10 declare i8 @llvm.vector.reduce.add.v16i8(<16 x i8>)
11 declare i8 @llvm.vector.reduce.add.v32i8(<32 x i8>)
12 declare i16 @llvm.vector.reduce.add.v2i16(<2 x i16>)
13 declare i16 @llvm.vector.reduce.add.v3i16(<3 x i16>)
14 declare i16 @llvm.vector.reduce.add.v4i16(<4 x i16>)
15 declare i16 @llvm.vector.reduce.add.v8i16(<8 x i16>)
16 declare i16 @llvm.vector.reduce.add.v16i16(<16 x i16>)
17 declare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>)
18 declare i32 @llvm.vector.reduce.add.v3i32(<3 x i32>)
19 declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>)
20 declare i32 @llvm.vector.reduce.add.v8i32(<8 x i32>)
21 declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>)
22 declare i64 @llvm.vector.reduce.add.v3i64(<3 x i64>)
23 declare i64 @llvm.vector.reduce.add.v4i64(<4 x i64>)
24 declare i128 @llvm.vector.reduce.add.v2i128(<2 x i128>)
26 ; GISEL: warning: Instruction selection used fallback path for addv_v2i8
27 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v3i8
28 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v4i8
29 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v2i16
30 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v3i16
31 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v3i32
32 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v3i64
33 ; GISEL-NEXT: warning: Instruction selection used fallback path for addv_v2i128
36 define i8 @add_B(ptr %arr) {
39 ; CHECK-NEXT: ldr q0, [x0]
40 ; CHECK-NEXT: addv b0, v0.16b
41 ; CHECK-NEXT: fmov w0, s0
43 %bin.rdx = load <16 x i8>, ptr %arr
44 %r = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %bin.rdx)
48 define i16 @add_H(ptr %arr) {
51 ; CHECK-NEXT: ldr q0, [x0]
52 ; CHECK-NEXT: addv h0, v0.8h
53 ; CHECK-NEXT: fmov w0, s0
55 %bin.rdx = load <8 x i16>, ptr %arr
56 %r = call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> %bin.rdx)
60 define i32 @add_S( ptr %arr) {
63 ; CHECK-NEXT: ldr q0, [x0]
64 ; CHECK-NEXT: addv s0, v0.4s
65 ; CHECK-NEXT: fmov w0, s0
67 %bin.rdx = load <4 x i32>, ptr %arr
68 %r = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
72 define i64 @add_D(ptr %arr) {
75 ; CHECK-NEXT: ldr q0, [x0]
76 ; CHECK-NEXT: addp d0, v0.2d
77 ; CHECK-NEXT: fmov x0, d0
79 %bin.rdx = load <2 x i64>, ptr %arr
80 %r = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
85 define i32 @oversized_ADDV_256(ptr noalias nocapture readonly %arg1, ptr noalias nocapture readonly %arg2) {
86 ; SDAG-LABEL: oversized_ADDV_256:
87 ; SDAG: // %bb.0: // %entry
88 ; SDAG-NEXT: ldr d0, [x0]
89 ; SDAG-NEXT: ldr d1, [x1]
90 ; SDAG-NEXT: uabdl v0.8h, v0.8b, v1.8b
91 ; SDAG-NEXT: uaddlv s0, v0.8h
92 ; SDAG-NEXT: fmov w0, s0
95 ; GISEL-LABEL: oversized_ADDV_256:
96 ; GISEL: // %bb.0: // %entry
97 ; GISEL-NEXT: ldr d1, [x0]
98 ; GISEL-NEXT: ldr d2, [x1]
99 ; GISEL-NEXT: movi v0.2d, #0000000000000000
100 ; GISEL-NEXT: usubl v1.8h, v1.8b, v2.8b
101 ; GISEL-NEXT: sshll v2.4s, v1.4h, #0
102 ; GISEL-NEXT: sshll2 v3.4s, v1.8h, #0
103 ; GISEL-NEXT: ssubw2 v0.4s, v0.4s, v1.8h
104 ; GISEL-NEXT: cmlt v4.4s, v2.4s, #0
105 ; GISEL-NEXT: cmlt v5.4s, v3.4s, #0
106 ; GISEL-NEXT: neg v6.4s, v2.4s
107 ; GISEL-NEXT: mov v1.16b, v4.16b
108 ; GISEL-NEXT: bif v0.16b, v3.16b, v5.16b
109 ; GISEL-NEXT: bsl v1.16b, v6.16b, v2.16b
110 ; GISEL-NEXT: add v0.4s, v1.4s, v0.4s
111 ; GISEL-NEXT: addv s0, v0.4s
112 ; GISEL-NEXT: fmov w0, s0
115 %0 = load <8 x i8>, ptr %arg1, align 1
116 %1 = zext <8 x i8> %0 to <8 x i32>
117 %2 = load <8 x i8>, ptr %arg2, align 1
118 %3 = zext <8 x i8> %2 to <8 x i32>
119 %4 = sub nsw <8 x i32> %1, %3
120 %5 = icmp slt <8 x i32> %4, zeroinitializer
121 %6 = sub nsw <8 x i32> zeroinitializer, %4
122 %7 = select <8 x i1> %5, <8 x i32> %6, <8 x i32> %4
123 %r = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %7)
127 declare i32 @llvm.vector.reduce.add.v16i32(<16 x i32>)
129 define i32 @oversized_ADDV_512(ptr %arr) {
130 ; SDAG-LABEL: oversized_ADDV_512:
132 ; SDAG-NEXT: ldp q0, q1, [x0, #32]
133 ; SDAG-NEXT: ldp q2, q3, [x0]
134 ; SDAG-NEXT: add v1.4s, v3.4s, v1.4s
135 ; SDAG-NEXT: add v0.4s, v2.4s, v0.4s
136 ; SDAG-NEXT: add v0.4s, v0.4s, v1.4s
137 ; SDAG-NEXT: addv s0, v0.4s
138 ; SDAG-NEXT: fmov w0, s0
141 ; GISEL-LABEL: oversized_ADDV_512:
143 ; GISEL-NEXT: ldp q0, q1, [x0]
144 ; GISEL-NEXT: ldp q2, q3, [x0, #32]
145 ; GISEL-NEXT: add v0.4s, v0.4s, v1.4s
146 ; GISEL-NEXT: add v1.4s, v2.4s, v3.4s
147 ; GISEL-NEXT: add v0.4s, v0.4s, v1.4s
148 ; GISEL-NEXT: addv s0, v0.4s
149 ; GISEL-NEXT: fmov w0, s0
151 %bin.rdx = load <16 x i32>, ptr %arr
152 %r = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %bin.rdx)
156 define i8 @addv_combine_i8(<8 x i8> %a1, <8 x i8> %a2) {
157 ; SDAG-LABEL: addv_combine_i8:
158 ; SDAG: // %bb.0: // %entry
159 ; SDAG-NEXT: add v0.8b, v0.8b, v1.8b
160 ; SDAG-NEXT: addv b0, v0.8b
161 ; SDAG-NEXT: fmov w0, s0
164 ; GISEL-LABEL: addv_combine_i8:
165 ; GISEL: // %bb.0: // %entry
166 ; GISEL-NEXT: addv b0, v0.8b
167 ; GISEL-NEXT: addv b1, v1.8b
168 ; GISEL-NEXT: fmov w8, s0
169 ; GISEL-NEXT: fmov w9, s1
170 ; GISEL-NEXT: add w0, w9, w8, uxtb
173 %rdx.1 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a1)
174 %rdx.2 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a2)
175 %r = add i8 %rdx.1, %rdx.2
179 define i16 @addv_combine_i16(<4 x i16> %a1, <4 x i16> %a2) {
180 ; SDAG-LABEL: addv_combine_i16:
181 ; SDAG: // %bb.0: // %entry
182 ; SDAG-NEXT: add v0.4h, v0.4h, v1.4h
183 ; SDAG-NEXT: addv h0, v0.4h
184 ; SDAG-NEXT: fmov w0, s0
187 ; GISEL-LABEL: addv_combine_i16:
188 ; GISEL: // %bb.0: // %entry
189 ; GISEL-NEXT: addv h0, v0.4h
190 ; GISEL-NEXT: addv h1, v1.4h
191 ; GISEL-NEXT: fmov w8, s0
192 ; GISEL-NEXT: fmov w9, s1
193 ; GISEL-NEXT: add w0, w9, w8, uxth
196 %rdx.1 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a1)
197 %rdx.2 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a2)
198 %r = add i16 %rdx.1, %rdx.2
202 define i32 @addv_combine_i32(<4 x i32> %a1, <4 x i32> %a2) {
203 ; SDAG-LABEL: addv_combine_i32:
204 ; SDAG: // %bb.0: // %entry
205 ; SDAG-NEXT: add v0.4s, v0.4s, v1.4s
206 ; SDAG-NEXT: addv s0, v0.4s
207 ; SDAG-NEXT: fmov w0, s0
210 ; GISEL-LABEL: addv_combine_i32:
211 ; GISEL: // %bb.0: // %entry
212 ; GISEL-NEXT: addv s0, v0.4s
213 ; GISEL-NEXT: addv s1, v1.4s
214 ; GISEL-NEXT: fmov w8, s0
215 ; GISEL-NEXT: fmov w9, s1
216 ; GISEL-NEXT: add w0, w8, w9
219 %rdx.1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a1)
220 %rdx.2 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a2)
221 %r = add i32 %rdx.1, %rdx.2
225 define i64 @addv_combine_i64(<2 x i64> %a1, <2 x i64> %a2) {
226 ; SDAG-LABEL: addv_combine_i64:
227 ; SDAG: // %bb.0: // %entry
228 ; SDAG-NEXT: add v0.2d, v0.2d, v1.2d
229 ; SDAG-NEXT: addp d0, v0.2d
230 ; SDAG-NEXT: fmov x0, d0
233 ; GISEL-LABEL: addv_combine_i64:
234 ; GISEL: // %bb.0: // %entry
235 ; GISEL-NEXT: addp d0, v0.2d
236 ; GISEL-NEXT: addp d1, v1.2d
237 ; GISEL-NEXT: fmov x8, d0
238 ; GISEL-NEXT: fmov x9, d1
239 ; GISEL-NEXT: add x0, x8, x9
242 %rdx.1 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a1)
243 %rdx.2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a2)
244 %r = add i64 %rdx.1, %rdx.2
248 define i8 @addv_v2i8(<2 x i8> %a) {
249 ; CHECK-LABEL: addv_v2i8:
250 ; CHECK: // %bb.0: // %entry
251 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
252 ; CHECK-NEXT: fmov w0, s0
255 %arg1 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> %a)
259 define i8 @addv_v3i8(<3 x i8> %a) {
260 ; CHECK-LABEL: addv_v3i8:
261 ; CHECK: // %bb.0: // %entry
262 ; CHECK-NEXT: movi v0.2d, #0000000000000000
263 ; CHECK-NEXT: mov v0.h[0], w0
264 ; CHECK-NEXT: mov v0.h[1], w1
265 ; CHECK-NEXT: mov v0.h[2], w2
266 ; CHECK-NEXT: addv h0, v0.4h
267 ; CHECK-NEXT: fmov w0, s0
270 %arg1 = call i8 @llvm.vector.reduce.add.v3i8(<3 x i8> %a)
274 define i8 @addv_v4i8(<4 x i8> %a) {
275 ; CHECK-LABEL: addv_v4i8:
276 ; CHECK: // %bb.0: // %entry
277 ; CHECK-NEXT: addv h0, v0.4h
278 ; CHECK-NEXT: fmov w0, s0
281 %arg1 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> %a)
285 define i8 @addv_v8i8(<8 x i8> %a) {
286 ; CHECK-LABEL: addv_v8i8:
287 ; CHECK: // %bb.0: // %entry
288 ; CHECK-NEXT: addv b0, v0.8b
289 ; CHECK-NEXT: fmov w0, s0
292 %arg1 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a)
296 define i8 @addv_v16i8(<16 x i8> %a) {
297 ; CHECK-LABEL: addv_v16i8:
298 ; CHECK: // %bb.0: // %entry
299 ; CHECK-NEXT: addv b0, v0.16b
300 ; CHECK-NEXT: fmov w0, s0
303 %arg1 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %a)
307 define i8 @addv_v32i8(<32 x i8> %a) {
308 ; CHECK-LABEL: addv_v32i8:
309 ; CHECK: // %bb.0: // %entry
310 ; CHECK-NEXT: add v0.16b, v0.16b, v1.16b
311 ; CHECK-NEXT: addv b0, v0.16b
312 ; CHECK-NEXT: fmov w0, s0
315 %arg1 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> %a)
319 define i16 @addv_v2i16(<2 x i16> %a) {
320 ; CHECK-LABEL: addv_v2i16:
321 ; CHECK: // %bb.0: // %entry
322 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
323 ; CHECK-NEXT: fmov w0, s0
326 %arg1 = call i16 @llvm.vector.reduce.add.v2i16(<2 x i16> %a)
330 define i16 @addv_v3i16(<3 x i16> %a) {
331 ; CHECK-LABEL: addv_v3i16:
332 ; CHECK: // %bb.0: // %entry
333 ; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
334 ; CHECK-NEXT: mov v0.h[3], wzr
335 ; CHECK-NEXT: addv h0, v0.4h
336 ; CHECK-NEXT: fmov w0, s0
339 %arg1 = call i16 @llvm.vector.reduce.add.v3i16(<3 x i16> %a)
343 define i16 @addv_v4i16(<4 x i16> %a) {
344 ; CHECK-LABEL: addv_v4i16:
345 ; CHECK: // %bb.0: // %entry
346 ; CHECK-NEXT: addv h0, v0.4h
347 ; CHECK-NEXT: fmov w0, s0
350 %arg1 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a)
354 define i16 @addv_v8i16(<8 x i16> %a) {
355 ; CHECK-LABEL: addv_v8i16:
356 ; CHECK: // %bb.0: // %entry
357 ; CHECK-NEXT: addv h0, v0.8h
358 ; CHECK-NEXT: fmov w0, s0
361 %arg1 = call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> %a)
365 define i16 @addv_v16i16(<16 x i16> %a) {
366 ; CHECK-LABEL: addv_v16i16:
367 ; CHECK: // %bb.0: // %entry
368 ; CHECK-NEXT: add v0.8h, v0.8h, v1.8h
369 ; CHECK-NEXT: addv h0, v0.8h
370 ; CHECK-NEXT: fmov w0, s0
373 %arg1 = call i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %a)
377 define i32 @addv_v2i32(<2 x i32> %a) {
378 ; CHECK-LABEL: addv_v2i32:
379 ; CHECK: // %bb.0: // %entry
380 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
381 ; CHECK-NEXT: fmov w0, s0
384 %arg1 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %a)
388 define i32 @addv_v3i32(<3 x i32> %a) {
389 ; CHECK-LABEL: addv_v3i32:
390 ; CHECK: // %bb.0: // %entry
391 ; CHECK-NEXT: mov v0.s[3], wzr
392 ; CHECK-NEXT: addv s0, v0.4s
393 ; CHECK-NEXT: fmov w0, s0
396 %arg1 = call i32 @llvm.vector.reduce.add.v3i32(<3 x i32> %a)
400 define i32 @addv_v4i32(<4 x i32> %a) {
401 ; CHECK-LABEL: addv_v4i32:
402 ; CHECK: // %bb.0: // %entry
403 ; CHECK-NEXT: addv s0, v0.4s
404 ; CHECK-NEXT: fmov w0, s0
407 %arg1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
411 define i32 @addv_v8i32(<8 x i32> %a) {
412 ; CHECK-LABEL: addv_v8i32:
413 ; CHECK: // %bb.0: // %entry
414 ; CHECK-NEXT: add v0.4s, v0.4s, v1.4s
415 ; CHECK-NEXT: addv s0, v0.4s
416 ; CHECK-NEXT: fmov w0, s0
419 %arg1 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %a)
423 define i64 @addv_v2i64(<2 x i64> %a) {
424 ; CHECK-LABEL: addv_v2i64:
425 ; CHECK: // %bb.0: // %entry
426 ; CHECK-NEXT: addp d0, v0.2d
427 ; CHECK-NEXT: fmov x0, d0
430 %arg1 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
434 define i64 @addv_v3i64(<3 x i64> %a) {
435 ; CHECK-LABEL: addv_v3i64:
436 ; CHECK: // %bb.0: // %entry
437 ; CHECK-NEXT: // kill: def $d2 killed $d2 def $q2
438 ; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
439 ; CHECK-NEXT: // kill: def $d1 killed $d1 def $q1
440 ; CHECK-NEXT: mov v0.d[1], v1.d[0]
441 ; CHECK-NEXT: mov v2.d[1], xzr
442 ; CHECK-NEXT: add v0.2d, v0.2d, v2.2d
443 ; CHECK-NEXT: addp d0, v0.2d
444 ; CHECK-NEXT: fmov x0, d0
447 %arg1 = call i64 @llvm.vector.reduce.add.v3i64(<3 x i64> %a)
451 define i64 @addv_v4i64(<4 x i64> %a) {
452 ; CHECK-LABEL: addv_v4i64:
453 ; CHECK: // %bb.0: // %entry
454 ; CHECK-NEXT: add v0.2d, v0.2d, v1.2d
455 ; CHECK-NEXT: addp d0, v0.2d
456 ; CHECK-NEXT: fmov x0, d0
459 %arg1 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %a)
463 define i128 @addv_v2i128(<2 x i128> %a) {
464 ; CHECK-LABEL: addv_v2i128:
465 ; CHECK: // %bb.0: // %entry
466 ; CHECK-NEXT: adds x0, x0, x2
467 ; CHECK-NEXT: adc x1, x1, x3
470 %arg1 = call i128 @llvm.vector.reduce.add.v2i128(<2 x i128> %a)