1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve,+bf16 < %s | FileCheck %s --check-prefixes=CHECK
4 ; Should codegen to a nop, since idx is zero.
5 define <2 x i64> @extract_v2i64_nxv2i64(<vscale x 2 x i64> %vec) nounwind {
6 ; CHECK-LABEL: extract_v2i64_nxv2i64:
8 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
10 %retval = call <2 x i64> @llvm.vector.extract.v2i64.nxv2i64(<vscale x 2 x i64> %vec, i64 0)
14 ; Goes through memory currently; idx != 0.
15 define <2 x i64> @extract_v2i64_nxv2i64_idx2(<vscale x 2 x i64> %vec) nounwind {
16 ; CHECK-LABEL: extract_v2i64_nxv2i64_idx2:
18 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #16
19 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
21 %retval = call <2 x i64> @llvm.vector.extract.v2i64.nxv2i64(<vscale x 2 x i64> %vec, i64 2)
25 ; Should codegen to a nop, since idx is zero.
26 define <4 x i32> @extract_v4i32_nxv4i32(<vscale x 4 x i32> %vec) nounwind {
27 ; CHECK-LABEL: extract_v4i32_nxv4i32:
29 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
31 %retval = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 0)
35 ; Goes through memory currently; idx != 0.
36 define <4 x i32> @extract_v4i32_nxv4i32_idx4(<vscale x 4 x i32> %vec) nounwind {
37 ; CHECK-LABEL: extract_v4i32_nxv4i32_idx4:
39 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #16
40 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
42 %retval = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %vec, i64 4)
46 ; Should codegen to uzps, since idx is zero and type is illegal.
47 define <4 x i32> @extract_v4i32_nxv2i32(<vscale x 2 x i32> %vec) nounwind #1 {
48 ; CHECK-LABEL: extract_v4i32_nxv2i32:
50 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
51 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
53 %retval = call <4 x i32> @llvm.vector.extract.v4i32.nxv2i32(<vscale x 2 x i32> %vec, i64 0)
57 ; Goes through memory currently; idx != 0.
58 define <4 x i32> @extract_v4i32_nxv2i32_idx4(<vscale x 2 x i32> %vec) nounwind #1 {
59 ; CHECK-LABEL: extract_v4i32_nxv2i32_idx4:
61 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #32
62 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
63 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
65 %retval = call <4 x i32> @llvm.vector.extract.v4i32.nxv2i32(<vscale x 2 x i32> %vec, i64 4)
69 ; Should codegen to a nop, since idx is zero.
70 define <8 x i16> @extract_v8i16_nxv8i16(<vscale x 8 x i16> %vec) nounwind {
71 ; CHECK-LABEL: extract_v8i16_nxv8i16:
73 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
75 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv8i16(<vscale x 8 x i16> %vec, i64 0)
79 ; Goes through memory currently; idx != 0.
80 define <8 x i16> @extract_v8i16_nxv8i16_idx8(<vscale x 8 x i16> %vec) nounwind {
81 ; CHECK-LABEL: extract_v8i16_nxv8i16_idx8:
83 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #16
84 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
86 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv8i16(<vscale x 8 x i16> %vec, i64 8)
90 ; Should codegen to uzps, since idx is zero and type is illegal.
91 define <8 x i16> @extract_v8i16_nxv4i16(<vscale x 4 x i16> %vec) nounwind #1 {
92 ; CHECK-LABEL: extract_v8i16_nxv4i16:
94 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
95 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
97 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv4i16(<vscale x 4 x i16> %vec, i64 0)
101 ; Goes through memory currently; idx != 0.
102 define <8 x i16> @extract_v8i16_nxv4i16_idx8(<vscale x 4 x i16> %vec) nounwind #1 {
103 ; CHECK-LABEL: extract_v8i16_nxv4i16_idx8:
105 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #32
106 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
107 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
109 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv4i16(<vscale x 4 x i16> %vec, i64 8)
110 ret <8 x i16> %retval
113 ; Should codegen to uzps, since idx is zero and type is illegal.
114 define <8 x i16> @extract_v8i16_nxv2i16(<vscale x 2 x i16> %vec) nounwind #1 {
115 ; CHECK-LABEL: extract_v8i16_nxv2i16:
117 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
118 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
119 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
121 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv2i16(<vscale x 2 x i16> %vec, i64 0)
122 ret <8 x i16> %retval
125 ; Goes through memory currently; idx != 0.
126 define <8 x i16> @extract_v8i16_nxv2i16_idx8(<vscale x 2 x i16> %vec) nounwind #1 {
127 ; CHECK-LABEL: extract_v8i16_nxv2i16_idx8:
129 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #64
130 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
131 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
132 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
134 %retval = call <8 x i16> @llvm.vector.extract.v8i16.nxv2i16(<vscale x 2 x i16> %vec, i64 8)
135 ret <8 x i16> %retval
138 ; Should codegen to a nop, since idx is zero.
139 define <16 x i8> @extract_v16i8_nxv16i8(<vscale x 16 x i8> %vec) nounwind {
140 ; CHECK-LABEL: extract_v16i8_nxv16i8:
142 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
144 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv16i8(<vscale x 16 x i8> %vec, i64 0)
145 ret <16 x i8> %retval
148 ; Goes through memory currently; idx != 0.
149 define <16 x i8> @extract_v16i8_nxv16i8_idx16(<vscale x 16 x i8> %vec) nounwind {
150 ; CHECK-LABEL: extract_v16i8_nxv16i8_idx16:
152 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #16
153 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
155 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv16i8(<vscale x 16 x i8> %vec, i64 16)
156 ret <16 x i8> %retval
159 ; Should codegen to uzps, since idx is zero and type is illegal.
160 define <16 x i8> @extract_v16i8_nxv8i8(<vscale x 8 x i8> %vec) nounwind #1 {
161 ; CHECK-LABEL: extract_v16i8_nxv8i8:
163 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
164 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
166 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv8i8(<vscale x 8 x i8> %vec, i64 0)
167 ret <16 x i8> %retval
170 ; Goes through memory currently; idx != 0.
171 define <16 x i8> @extract_v16i8_nxv8i8_idx16(<vscale x 8 x i8> %vec) nounwind #1 {
172 ; CHECK-LABEL: extract_v16i8_nxv8i8_idx16:
174 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #32
175 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
176 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
178 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv8i8(<vscale x 8 x i8> %vec, i64 16)
179 ret <16 x i8> %retval
182 ; Should codegen to uzps, since idx is zero and type is illegal.
183 define <16 x i8> @extract_v16i8_nxv4i8(<vscale x 4 x i8> %vec) nounwind #1 {
184 ; CHECK-LABEL: extract_v16i8_nxv4i8:
186 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
187 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
188 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
190 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv4i8(<vscale x 4 x i8> %vec, i64 0)
191 ret <16 x i8> %retval
194 ; Goes through memory currently; idx != 0.
195 define <16 x i8> @extract_v16i8_nxv4i8_idx16(<vscale x 4 x i8> %vec) nounwind #1 {
196 ; CHECK-LABEL: extract_v16i8_nxv4i8_idx16:
198 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #64
199 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
200 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
201 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
203 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv4i8(<vscale x 4 x i8> %vec, i64 16)
204 ret <16 x i8> %retval
207 ; Should codegen to uzps, since idx is zero and type is illegal.
208 define <16 x i8> @extract_v16i8_nxv2i8(<vscale x 2 x i8> %vec) nounwind #1 {
209 ; CHECK-LABEL: extract_v16i8_nxv2i8:
211 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
212 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
213 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
214 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
216 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv2i8(<vscale x 2 x i8> %vec, i64 0)
217 ret <16 x i8> %retval
220 ; Goes through memory currently; idx != 0.
221 define <16 x i8> @extract_v16i8_nxv2i8_idx16(<vscale x 2 x i8> %vec) nounwind #1 {
222 ; CHECK-LABEL: extract_v16i8_nxv2i8_idx16:
224 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #128
225 ; CHECK-NEXT: uzp1 z0.s, z0.s, z0.s
226 ; CHECK-NEXT: uzp1 z0.h, z0.h, z0.h
227 ; CHECK-NEXT: uzp1 z0.b, z0.b, z0.b
228 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
230 %retval = call <16 x i8> @llvm.vector.extract.v16i8.nxv2i8(<vscale x 2 x i8> %vec, i64 16)
231 ret <16 x i8> %retval
237 define <2 x i1> @extract_v2i1_nxv2i1(<vscale x 2 x i1> %inmask) {
238 ; CHECK-LABEL: extract_v2i1_nxv2i1:
240 ; CHECK-NEXT: mov z0.d, p0/z, #1 // =0x1
241 ; CHECK-NEXT: fmov x0, d0
242 ; CHECK-NEXT: mov x8, v0.d[1]
243 ; CHECK-NEXT: fmov s0, w0
244 ; CHECK-NEXT: mov v0.s[1], w8
245 ; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
247 %mask = call <2 x i1> @llvm.vector.extract.v2i1.nxv2i1(<vscale x 2 x i1> %inmask, i64 0)
251 define <4 x i1> @extract_v4i1_nxv4i1(<vscale x 4 x i1> %inmask) {
252 ; CHECK-LABEL: extract_v4i1_nxv4i1:
254 ; CHECK-NEXT: mov z1.s, p0/z, #1 // =0x1
255 ; CHECK-NEXT: mov w8, v1.s[1]
256 ; CHECK-NEXT: mov v0.16b, v1.16b
257 ; CHECK-NEXT: mov w9, v1.s[2]
258 ; CHECK-NEXT: mov v0.h[1], w8
259 ; CHECK-NEXT: mov w8, v1.s[3]
260 ; CHECK-NEXT: mov v0.h[2], w9
261 ; CHECK-NEXT: mov v0.h[3], w8
262 ; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
264 %mask = call <4 x i1> @llvm.vector.extract.v4i1.nxv4i1(<vscale x 4 x i1> %inmask, i64 0)
268 define <8 x i1> @extract_v8i1_nxv8i1(<vscale x 8 x i1> %inmask) {
269 ; CHECK-LABEL: extract_v8i1_nxv8i1:
271 ; CHECK-NEXT: mov z1.h, p0/z, #1 // =0x1
272 ; CHECK-NEXT: umov w8, v1.h[1]
273 ; CHECK-NEXT: mov v0.16b, v1.16b
274 ; CHECK-NEXT: umov w9, v1.h[2]
275 ; CHECK-NEXT: mov v0.b[1], w8
276 ; CHECK-NEXT: umov w8, v1.h[3]
277 ; CHECK-NEXT: mov v0.b[2], w9
278 ; CHECK-NEXT: umov w9, v1.h[4]
279 ; CHECK-NEXT: mov v0.b[3], w8
280 ; CHECK-NEXT: umov w8, v1.h[5]
281 ; CHECK-NEXT: mov v0.b[4], w9
282 ; CHECK-NEXT: umov w9, v1.h[6]
283 ; CHECK-NEXT: mov v0.b[5], w8
284 ; CHECK-NEXT: umov w8, v1.h[7]
285 ; CHECK-NEXT: mov v0.b[6], w9
286 ; CHECK-NEXT: mov v0.b[7], w8
287 ; CHECK-NEXT: // kill: def $d0 killed $d0 killed $q0
289 %mask = call <8 x i1> @llvm.vector.extract.v8i1.nxv8i1(<vscale x 8 x i1> %inmask, i64 0)
293 ; TODO: Apply better reasoning when lowering extract_subvector from the bottom 128-bits
295 define <16 x i1> @extract_v16i1_nxv16i1(<vscale x 16 x i1> %inmask) {
296 ; CHECK-LABEL: extract_v16i1_nxv16i1:
298 ; CHECK-NEXT: mov z1.b, p0/z, #1 // =0x1
299 ; CHECK-NEXT: mov v0.16b, v1.16b
300 ; CHECK-NEXT: mov v0.b[1], v1.b[1]
301 ; CHECK-NEXT: mov v0.b[2], v1.b[2]
302 ; CHECK-NEXT: mov v0.b[3], v1.b[3]
303 ; CHECK-NEXT: mov v0.b[4], v1.b[4]
304 ; CHECK-NEXT: mov v0.b[5], v1.b[5]
305 ; CHECK-NEXT: mov v0.b[6], v1.b[6]
306 ; CHECK-NEXT: mov v0.b[7], v1.b[7]
307 ; CHECK-NEXT: mov v0.b[8], v1.b[8]
308 ; CHECK-NEXT: mov v0.b[9], v1.b[9]
309 ; CHECK-NEXT: mov v0.b[10], v1.b[10]
310 ; CHECK-NEXT: mov v0.b[11], v1.b[11]
311 ; CHECK-NEXT: mov v0.b[12], v1.b[12]
312 ; CHECK-NEXT: mov v0.b[13], v1.b[13]
313 ; CHECK-NEXT: mov v0.b[14], v1.b[14]
314 ; CHECK-NEXT: mov v0.b[15], v1.b[15]
316 %mask = call <16 x i1> @llvm.vector.extract.v16i1.nxv16i1(<vscale x 16 x i1> %inmask, i64 0)
321 ; Fixed length clamping
323 define <2 x i64> @extract_fixed_v2i64_nxv2i64(<vscale x 2 x i64> %vec) nounwind #0 {
324 ; CHECK-LABEL: extract_fixed_v2i64_nxv2i64:
326 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #16
327 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
329 %retval = call <2 x i64> @llvm.vector.extract.v2i64.nxv2i64(<vscale x 2 x i64> %vec, i64 2)
330 ret <2 x i64> %retval
333 define void @extract_fixed_v4i64_nxv2i64(<vscale x 2 x i64> %vec, ptr %p) nounwind #0 {
334 ; CHECK-LABEL: extract_fixed_v4i64_nxv2i64:
336 ; CHECK-NEXT: ext z0.b, z0.b, z0.b, #32
337 ; CHECK-NEXT: ptrue p0.d
338 ; CHECK-NEXT: st1d { z0.d }, p0, [x0]
340 %retval = call <4 x i64> @llvm.vector.extract.v4i64.nxv2i64(<vscale x 2 x i64> %vec, i64 4)
341 store <4 x i64> %retval, ptr %p
345 ; Check that extract from load via bitcast-gep-of-scalar-ptr does not crash.
346 define <4 x i32> @typesize_regression_test_v4i32(ptr %addr, i64 %idx) {
347 ; CHECK-LABEL: typesize_regression_test_v4i32:
348 ; CHECK: // %bb.0: // %entry
349 ; CHECK-NEXT: ptrue p0.s
350 ; CHECK-NEXT: ld1w { z0.s }, p0/z, [x0, x1, lsl #2]
351 ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0
354 %ptr = getelementptr inbounds i32, ptr %addr, i64 %idx
355 %bc = bitcast ptr %ptr to ptr
356 %ld = load volatile <vscale x 4 x i32>, ptr %bc, align 16
357 %out = call <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %ld, i64 0)
362 ; Extract fixed-width vector from a scalable vector splat.
365 define <2 x float> @extract_v2f32_nxv4f32_splat(float %f) {
366 ; CHECK-LABEL: extract_v2f32_nxv4f32_splat:
368 ; CHECK-NEXT: // kill: def $s0 killed $s0 def $q0
369 ; CHECK-NEXT: dup v0.2s, v0.s[0]
371 %ins = insertelement <vscale x 4 x float> poison, float %f, i32 0
372 %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer
373 %ext = call <2 x float> @llvm.vector.extract.v2f32.nxv4f32(<vscale x 4 x float> %splat, i64 0)
377 define <2 x float> @extract_v2f32_nxv4f32_splat_const() {
378 ; CHECK-LABEL: extract_v2f32_nxv4f32_splat_const:
380 ; CHECK-NEXT: fmov v0.2s, #1.00000000
382 %ext = call <2 x float> @llvm.vector.extract.v2f32.nxv4f32(<vscale x 4 x float> splat(float 1.0), i64 0)
386 define <4 x i32> @extract_v4i32_nxv8i32_splat_const() {
387 ; CHECK-LABEL: extract_v4i32_nxv8i32_splat_const:
389 ; CHECK-NEXT: movi v0.4s, #1
391 %ext = call <4 x i32> @llvm.vector.extract.v4i32.nxv8i32(<vscale x 8 x i32> splat(i32 1), i64 0)
395 attributes #0 = { vscale_range(2,2) }
396 attributes #1 = { vscale_range(8,8) }
398 declare <2 x i64> @llvm.vector.extract.v2i64.nxv2i64(<vscale x 2 x i64>, i64)
400 declare <4 x i32> @llvm.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32>, i64)
401 declare <4 x i32> @llvm.vector.extract.v4i32.nxv2i32(<vscale x 2 x i32>, i64)
403 declare <8 x i16> @llvm.vector.extract.v8i16.nxv8i16(<vscale x 8 x i16>, i64)
404 declare <8 x i16> @llvm.vector.extract.v8i16.nxv4i16(<vscale x 4 x i16>, i64)
405 declare <8 x i16> @llvm.vector.extract.v8i16.nxv2i16(<vscale x 2 x i16>, i64)
407 declare <16 x i8> @llvm.vector.extract.v16i8.nxv16i8(<vscale x 16 x i8>, i64)
408 declare <16 x i8> @llvm.vector.extract.v16i8.nxv8i8(<vscale x 8 x i8>, i64)
409 declare <16 x i8> @llvm.vector.extract.v16i8.nxv4i8(<vscale x 4 x i8>, i64)
410 declare <16 x i8> @llvm.vector.extract.v16i8.nxv2i8(<vscale x 2 x i8>, i64)
412 declare <2 x i1> @llvm.vector.extract.v2i1.nxv2i1(<vscale x 2 x i1>, i64)
413 declare <4 x i1> @llvm.vector.extract.v4i1.nxv4i1(<vscale x 4 x i1>, i64)
414 declare <8 x i1> @llvm.vector.extract.v8i1.nxv8i1(<vscale x 8 x i1>, i64)
415 declare <16 x i1> @llvm.vector.extract.v16i1.nxv16i1(<vscale x 16 x i1>, i64)
417 declare <4 x i64> @llvm.vector.extract.v4i64.nxv2i64(<vscale x 2 x i64>, i64)
418 declare <2 x float> @llvm.vector.extract.v2f32.nxv4f32(<vscale x 4 x float>, i64)
419 declare <4 x i32> @llvm.vector.extract.v4i32.nxv8i32(<vscale x 8 x i32>, i64)