1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-eabi -aarch64-neon-syntax=generic | FileCheck %s -check-prefixes=CHECK,SDAG
3 ; RUN: llc < %s -global-isel=1 -global-isel-abort=2 -mtriple=aarch64-eabi -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: ushll v1.8h, v1.8b, #0
101 ; GISEL-NEXT: ushll v2.8h, v2.8b, #0
102 ; GISEL-NEXT: usubl v3.4s, v1.4h, v2.4h
103 ; GISEL-NEXT: usubl2 v1.4s, v1.8h, v2.8h
104 ; GISEL-NEXT: cmgt v2.4s, v0.4s, v3.4s
105 ; GISEL-NEXT: cmgt v0.4s, v0.4s, v1.4s
106 ; GISEL-NEXT: neg v4.4s, v3.4s
107 ; GISEL-NEXT: neg v5.4s, v1.4s
108 ; GISEL-NEXT: shl v2.4s, v2.4s, #31
109 ; GISEL-NEXT: shl v0.4s, v0.4s, #31
110 ; GISEL-NEXT: sshr v2.4s, v2.4s, #31
111 ; GISEL-NEXT: sshr v0.4s, v0.4s, #31
112 ; GISEL-NEXT: bsl v2.16b, v4.16b, v3.16b
113 ; GISEL-NEXT: bsl v0.16b, v5.16b, v1.16b
114 ; GISEL-NEXT: add v0.4s, v2.4s, v0.4s
115 ; GISEL-NEXT: addv s0, v0.4s
116 ; GISEL-NEXT: fmov w0, s0
119 %0 = load <8 x i8>, ptr %arg1, align 1
120 %1 = zext <8 x i8> %0 to <8 x i32>
121 %2 = load <8 x i8>, ptr %arg2, align 1
122 %3 = zext <8 x i8> %2 to <8 x i32>
123 %4 = sub nsw <8 x i32> %1, %3
124 %5 = icmp slt <8 x i32> %4, zeroinitializer
125 %6 = sub nsw <8 x i32> zeroinitializer, %4
126 %7 = select <8 x i1> %5, <8 x i32> %6, <8 x i32> %4
127 %r = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %7)
131 declare i32 @llvm.vector.reduce.add.v16i32(<16 x i32>)
133 define i32 @oversized_ADDV_512(ptr %arr) {
134 ; SDAG-LABEL: oversized_ADDV_512:
136 ; SDAG-NEXT: ldp q0, q1, [x0, #32]
137 ; SDAG-NEXT: ldp q2, q3, [x0]
138 ; SDAG-NEXT: add v1.4s, v3.4s, v1.4s
139 ; SDAG-NEXT: add v0.4s, v2.4s, v0.4s
140 ; SDAG-NEXT: add v0.4s, v0.4s, v1.4s
141 ; SDAG-NEXT: addv s0, v0.4s
142 ; SDAG-NEXT: fmov w0, s0
145 ; GISEL-LABEL: oversized_ADDV_512:
147 ; GISEL-NEXT: ldp q0, q1, [x0]
148 ; GISEL-NEXT: ldp q2, q3, [x0, #32]
149 ; GISEL-NEXT: add v0.4s, v0.4s, v1.4s
150 ; GISEL-NEXT: add v1.4s, v2.4s, v3.4s
151 ; GISEL-NEXT: add v0.4s, v0.4s, v1.4s
152 ; GISEL-NEXT: addv s0, v0.4s
153 ; GISEL-NEXT: fmov w0, s0
155 %bin.rdx = load <16 x i32>, ptr %arr
156 %r = call i32 @llvm.vector.reduce.add.v16i32(<16 x i32> %bin.rdx)
160 define i8 @addv_combine_i8(<8 x i8> %a1, <8 x i8> %a2) {
161 ; SDAG-LABEL: addv_combine_i8:
162 ; SDAG: // %bb.0: // %entry
163 ; SDAG-NEXT: add v0.8b, v0.8b, v1.8b
164 ; SDAG-NEXT: addv b0, v0.8b
165 ; SDAG-NEXT: fmov w0, s0
168 ; GISEL-LABEL: addv_combine_i8:
169 ; GISEL: // %bb.0: // %entry
170 ; GISEL-NEXT: addv b0, v0.8b
171 ; GISEL-NEXT: addv b1, v1.8b
172 ; GISEL-NEXT: fmov w8, s0
173 ; GISEL-NEXT: fmov w9, s1
174 ; GISEL-NEXT: add w0, w9, w8, uxtb
177 %rdx.1 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a1)
178 %rdx.2 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a2)
179 %r = add i8 %rdx.1, %rdx.2
183 define i16 @addv_combine_i16(<4 x i16> %a1, <4 x i16> %a2) {
184 ; SDAG-LABEL: addv_combine_i16:
185 ; SDAG: // %bb.0: // %entry
186 ; SDAG-NEXT: add v0.4h, v0.4h, v1.4h
187 ; SDAG-NEXT: addv h0, v0.4h
188 ; SDAG-NEXT: fmov w0, s0
191 ; GISEL-LABEL: addv_combine_i16:
192 ; GISEL: // %bb.0: // %entry
193 ; GISEL-NEXT: addv h0, v0.4h
194 ; GISEL-NEXT: addv h1, v1.4h
195 ; GISEL-NEXT: fmov w8, s0
196 ; GISEL-NEXT: fmov w9, s1
197 ; GISEL-NEXT: add w0, w9, w8, uxth
200 %rdx.1 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a1)
201 %rdx.2 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a2)
202 %r = add i16 %rdx.1, %rdx.2
206 define i32 @addv_combine_i32(<4 x i32> %a1, <4 x i32> %a2) {
207 ; SDAG-LABEL: addv_combine_i32:
208 ; SDAG: // %bb.0: // %entry
209 ; SDAG-NEXT: add v0.4s, v0.4s, v1.4s
210 ; SDAG-NEXT: addv s0, v0.4s
211 ; SDAG-NEXT: fmov w0, s0
214 ; GISEL-LABEL: addv_combine_i32:
215 ; GISEL: // %bb.0: // %entry
216 ; GISEL-NEXT: addv s0, v0.4s
217 ; GISEL-NEXT: addv s1, v1.4s
218 ; GISEL-NEXT: fmov w8, s0
219 ; GISEL-NEXT: fmov w9, s1
220 ; GISEL-NEXT: add w0, w8, w9
223 %rdx.1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a1)
224 %rdx.2 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a2)
225 %r = add i32 %rdx.1, %rdx.2
229 define i64 @addv_combine_i64(<2 x i64> %a1, <2 x i64> %a2) {
230 ; SDAG-LABEL: addv_combine_i64:
231 ; SDAG: // %bb.0: // %entry
232 ; SDAG-NEXT: add v0.2d, v0.2d, v1.2d
233 ; SDAG-NEXT: addp d0, v0.2d
234 ; SDAG-NEXT: fmov x0, d0
237 ; GISEL-LABEL: addv_combine_i64:
238 ; GISEL: // %bb.0: // %entry
239 ; GISEL-NEXT: addp d0, v0.2d
240 ; GISEL-NEXT: addp d1, v1.2d
241 ; GISEL-NEXT: fmov x8, d0
242 ; GISEL-NEXT: fmov x9, d1
243 ; GISEL-NEXT: add x0, x8, x9
246 %rdx.1 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a1)
247 %rdx.2 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a2)
248 %r = add i64 %rdx.1, %rdx.2
252 define i8 @addv_v2i8(<2 x i8> %a) {
253 ; CHECK-LABEL: addv_v2i8:
254 ; CHECK: // %bb.0: // %entry
255 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
256 ; CHECK-NEXT: fmov w0, s0
259 %arg1 = call i8 @llvm.vector.reduce.add.v2i8(<2 x i8> %a)
263 define i8 @addv_v3i8(<3 x i8> %a) {
264 ; CHECK-LABEL: addv_v3i8:
265 ; CHECK: // %bb.0: // %entry
266 ; CHECK-NEXT: movi v0.2d, #0000000000000000
267 ; CHECK-NEXT: mov v0.h[0], w0
268 ; CHECK-NEXT: mov v0.h[1], w1
269 ; CHECK-NEXT: mov v0.h[2], w2
270 ; CHECK-NEXT: addv h0, v0.4h
271 ; CHECK-NEXT: fmov w0, s0
274 %arg1 = call i8 @llvm.vector.reduce.add.v3i8(<3 x i8> %a)
278 define i8 @addv_v4i8(<4 x i8> %a) {
279 ; CHECK-LABEL: addv_v4i8:
280 ; CHECK: // %bb.0: // %entry
281 ; CHECK-NEXT: addv h0, v0.4h
282 ; CHECK-NEXT: fmov w0, s0
285 %arg1 = call i8 @llvm.vector.reduce.add.v4i8(<4 x i8> %a)
289 define i8 @addv_v8i8(<8 x i8> %a) {
290 ; CHECK-LABEL: addv_v8i8:
291 ; CHECK: // %bb.0: // %entry
292 ; CHECK-NEXT: addv b0, v0.8b
293 ; CHECK-NEXT: fmov w0, s0
296 %arg1 = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a)
300 define i8 @addv_v16i8(<16 x i8> %a) {
301 ; CHECK-LABEL: addv_v16i8:
302 ; CHECK: // %bb.0: // %entry
303 ; CHECK-NEXT: addv b0, v0.16b
304 ; CHECK-NEXT: fmov w0, s0
307 %arg1 = call i8 @llvm.vector.reduce.add.v16i8(<16 x i8> %a)
311 define i8 @addv_v32i8(<32 x i8> %a) {
312 ; CHECK-LABEL: addv_v32i8:
313 ; CHECK: // %bb.0: // %entry
314 ; CHECK-NEXT: add v0.16b, v0.16b, v1.16b
315 ; CHECK-NEXT: addv b0, v0.16b
316 ; CHECK-NEXT: fmov w0, s0
319 %arg1 = call i8 @llvm.vector.reduce.add.v32i8(<32 x i8> %a)
323 define i16 @addv_v2i16(<2 x i16> %a) {
324 ; CHECK-LABEL: addv_v2i16:
325 ; CHECK: // %bb.0: // %entry
326 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
327 ; CHECK-NEXT: fmov w0, s0
330 %arg1 = call i16 @llvm.vector.reduce.add.v2i16(<2 x i16> %a)
334 define i16 @addv_v3i16(<3 x i16> %a) {
335 ; CHECK-LABEL: addv_v3i16:
336 ; CHECK: // %bb.0: // %entry
337 ; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
338 ; CHECK-NEXT: mov v0.h[3], wzr
339 ; CHECK-NEXT: addv h0, v0.4h
340 ; CHECK-NEXT: fmov w0, s0
343 %arg1 = call i16 @llvm.vector.reduce.add.v3i16(<3 x i16> %a)
347 define i16 @addv_v4i16(<4 x i16> %a) {
348 ; CHECK-LABEL: addv_v4i16:
349 ; CHECK: // %bb.0: // %entry
350 ; CHECK-NEXT: addv h0, v0.4h
351 ; CHECK-NEXT: fmov w0, s0
354 %arg1 = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> %a)
358 define i16 @addv_v8i16(<8 x i16> %a) {
359 ; CHECK-LABEL: addv_v8i16:
360 ; CHECK: // %bb.0: // %entry
361 ; CHECK-NEXT: addv h0, v0.8h
362 ; CHECK-NEXT: fmov w0, s0
365 %arg1 = call i16 @llvm.vector.reduce.add.v8i16(<8 x i16> %a)
369 define i16 @addv_v16i16(<16 x i16> %a) {
370 ; CHECK-LABEL: addv_v16i16:
371 ; CHECK: // %bb.0: // %entry
372 ; CHECK-NEXT: add v0.8h, v0.8h, v1.8h
373 ; CHECK-NEXT: addv h0, v0.8h
374 ; CHECK-NEXT: fmov w0, s0
377 %arg1 = call i16 @llvm.vector.reduce.add.v16i16(<16 x i16> %a)
381 define i32 @addv_v2i32(<2 x i32> %a) {
382 ; CHECK-LABEL: addv_v2i32:
383 ; CHECK: // %bb.0: // %entry
384 ; CHECK-NEXT: addp v0.2s, v0.2s, v0.2s
385 ; CHECK-NEXT: fmov w0, s0
388 %arg1 = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %a)
392 define i32 @addv_v3i32(<3 x i32> %a) {
393 ; CHECK-LABEL: addv_v3i32:
394 ; CHECK: // %bb.0: // %entry
395 ; CHECK-NEXT: mov v0.s[3], wzr
396 ; CHECK-NEXT: addv s0, v0.4s
397 ; CHECK-NEXT: fmov w0, s0
400 %arg1 = call i32 @llvm.vector.reduce.add.v3i32(<3 x i32> %a)
404 define i32 @addv_v4i32(<4 x i32> %a) {
405 ; CHECK-LABEL: addv_v4i32:
406 ; CHECK: // %bb.0: // %entry
407 ; CHECK-NEXT: addv s0, v0.4s
408 ; CHECK-NEXT: fmov w0, s0
411 %arg1 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %a)
415 define i32 @addv_v8i32(<8 x i32> %a) {
416 ; CHECK-LABEL: addv_v8i32:
417 ; CHECK: // %bb.0: // %entry
418 ; CHECK-NEXT: add v0.4s, v0.4s, v1.4s
419 ; CHECK-NEXT: addv s0, v0.4s
420 ; CHECK-NEXT: fmov w0, s0
423 %arg1 = call i32 @llvm.vector.reduce.add.v8i32(<8 x i32> %a)
427 define i64 @addv_v2i64(<2 x i64> %a) {
428 ; CHECK-LABEL: addv_v2i64:
429 ; CHECK: // %bb.0: // %entry
430 ; CHECK-NEXT: addp d0, v0.2d
431 ; CHECK-NEXT: fmov x0, d0
434 %arg1 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %a)
438 define i64 @addv_v3i64(<3 x i64> %a) {
439 ; CHECK-LABEL: addv_v3i64:
440 ; CHECK: // %bb.0: // %entry
441 ; CHECK-NEXT: // kill: def $d2 killed $d2 def $q2
442 ; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
443 ; CHECK-NEXT: // kill: def $d1 killed $d1 def $q1
444 ; CHECK-NEXT: mov v0.d[1], v1.d[0]
445 ; CHECK-NEXT: mov v2.d[1], xzr
446 ; CHECK-NEXT: add v0.2d, v0.2d, v2.2d
447 ; CHECK-NEXT: addp d0, v0.2d
448 ; CHECK-NEXT: fmov x0, d0
451 %arg1 = call i64 @llvm.vector.reduce.add.v3i64(<3 x i64> %a)
455 define i64 @addv_v4i64(<4 x i64> %a) {
456 ; CHECK-LABEL: addv_v4i64:
457 ; CHECK: // %bb.0: // %entry
458 ; CHECK-NEXT: add v0.2d, v0.2d, v1.2d
459 ; CHECK-NEXT: addp d0, v0.2d
460 ; CHECK-NEXT: fmov x0, d0
463 %arg1 = call i64 @llvm.vector.reduce.add.v4i64(<4 x i64> %a)
467 define i128 @addv_v2i128(<2 x i128> %a) {
468 ; CHECK-LABEL: addv_v2i128:
469 ; CHECK: // %bb.0: // %entry
470 ; CHECK-NEXT: adds x0, x0, x2
471 ; CHECK-NEXT: adc x1, x1, x3
474 %arg1 = call i128 @llvm.vector.reduce.add.v2i128(<2 x i128> %a)