1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+zvfh,+v -verify-machineinstrs < %s | FileCheck %s
4 define <4 x i8> @ret_v4i8(ptr %p) {
5 ; CHECK-LABEL: ret_v4i8:
7 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
8 ; CHECK-NEXT: vle8.v v8, (a0)
10 %v = load <4 x i8>, ptr %p
14 define <4 x i32> @ret_v4i32(ptr %p) {
15 ; CHECK-LABEL: ret_v4i32:
17 ; CHECK-NEXT: vsetivli zero, 4, e32, m1, ta, ma
18 ; CHECK-NEXT: vle32.v v8, (a0)
20 %v = load <4 x i32>, ptr %p
24 define <8 x i32> @ret_v8i32(ptr %p) {
25 ; CHECK-LABEL: ret_v8i32:
27 ; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma
28 ; CHECK-NEXT: vle32.v v8, (a0)
30 %v = load <8 x i32>, ptr %p
34 define <16 x i64> @ret_v16i64(ptr %p) {
35 ; CHECK-LABEL: ret_v16i64:
37 ; CHECK-NEXT: vsetivli zero, 16, e64, m8, ta, ma
38 ; CHECK-NEXT: vle64.v v8, (a0)
40 %v = load <16 x i64>, ptr %p
44 define <8 x i1> @ret_mask_v8i1(ptr %p) {
45 ; CHECK-LABEL: ret_mask_v8i1:
47 ; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
48 ; CHECK-NEXT: vlm.v v0, (a0)
50 %v = load <8 x i1>, ptr %p
54 define <32 x i1> @ret_mask_v32i1(ptr %p) {
55 ; CHECK-LABEL: ret_mask_v32i1:
57 ; CHECK-NEXT: li a1, 32
58 ; CHECK-NEXT: vsetvli zero, a1, e8, m2, ta, ma
59 ; CHECK-NEXT: vlm.v v0, (a0)
61 %v = load <32 x i1>, ptr %p
65 ; Return the vector via registers v8-v23
66 define <64 x i32> @ret_split_v64i32(ptr %x) {
67 ; CHECK-LABEL: ret_split_v64i32:
69 ; CHECK-NEXT: li a1, 32
70 ; CHECK-NEXT: vsetvli zero, a1, e32, m8, ta, ma
71 ; CHECK-NEXT: vle32.v v8, (a0)
72 ; CHECK-NEXT: addi a0, a0, 128
73 ; CHECK-NEXT: vle32.v v16, (a0)
75 %v = load <64 x i32>, ptr %x
79 ; Return the vector fully via the stack
80 define <128 x i32> @ret_split_v128i32(ptr %x) {
81 ; CHECK-LABEL: ret_split_v128i32:
83 ; CHECK-NEXT: addi a2, a1, 128
84 ; CHECK-NEXT: li a3, 32
85 ; CHECK-NEXT: vsetvli zero, a3, e32, m8, ta, ma
86 ; CHECK-NEXT: vle32.v v8, (a2)
87 ; CHECK-NEXT: addi a2, a1, 256
88 ; CHECK-NEXT: vle32.v v16, (a1)
89 ; CHECK-NEXT: addi a1, a1, 384
90 ; CHECK-NEXT: vle32.v v24, (a1)
91 ; CHECK-NEXT: vle32.v v0, (a2)
92 ; CHECK-NEXT: vse32.v v16, (a0)
93 ; CHECK-NEXT: addi a1, a0, 384
94 ; CHECK-NEXT: vse32.v v24, (a1)
95 ; CHECK-NEXT: addi a1, a0, 256
96 ; CHECK-NEXT: vse32.v v0, (a1)
97 ; CHECK-NEXT: addi a0, a0, 128
98 ; CHECK-NEXT: vse32.v v8, (a0)
100 %v = load <128 x i32>, ptr %x
104 define <4 x i8> @ret_v8i8_param_v4i8(<4 x i8> %v) {
105 ; CHECK-LABEL: ret_v8i8_param_v4i8:
107 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
108 ; CHECK-NEXT: vadd.vi v8, v8, 2
110 %r = add <4 x i8> %v, <i8 2, i8 2, i8 2, i8 2>
114 define <4 x i8> @ret_v4i8_param_v4i8_v4i8(<4 x i8> %v, <4 x i8> %w) {
115 ; CHECK-LABEL: ret_v4i8_param_v4i8_v4i8:
117 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
118 ; CHECK-NEXT: vadd.vv v8, v8, v9
120 %r = add <4 x i8> %v, %w
124 define <4 x i64> @ret_v4i64_param_v4i64_v4i64(<4 x i64> %v, <4 x i64> %w) {
125 ; CHECK-LABEL: ret_v4i64_param_v4i64_v4i64:
127 ; CHECK-NEXT: vsetivli zero, 4, e64, m2, ta, ma
128 ; CHECK-NEXT: vadd.vv v8, v8, v10
130 %r = add <4 x i64> %v, %w
134 define <8 x i1> @ret_v8i1_param_v8i1_v8i1(<8 x i1> %v, <8 x i1> %w) {
135 ; CHECK-LABEL: ret_v8i1_param_v8i1_v8i1:
137 ; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
138 ; CHECK-NEXT: vmxor.mm v0, v0, v8
140 %r = xor <8 x i1> %v, %w
144 define <32 x i1> @ret_v32i1_param_v32i1_v32i1(<32 x i1> %v, <32 x i1> %w) {
145 ; CHECK-LABEL: ret_v32i1_param_v32i1_v32i1:
147 ; CHECK-NEXT: li a0, 32
148 ; CHECK-NEXT: vsetvli zero, a0, e8, m2, ta, ma
149 ; CHECK-NEXT: vmand.mm v0, v0, v8
151 %r = and <32 x i1> %v, %w
155 define <32 x i32> @ret_v32i32_param_v32i32_v32i32_v32i32_i32(<32 x i32> %x, <32 x i32> %y, <32 x i32> %z, i32 %w) {
156 ; CHECK-LABEL: ret_v32i32_param_v32i32_v32i32_v32i32_i32:
158 ; CHECK-NEXT: li a2, 32
159 ; CHECK-NEXT: vsetvli zero, a2, e32, m8, ta, ma
160 ; CHECK-NEXT: vle32.v v24, (a0)
161 ; CHECK-NEXT: vadd.vv v8, v8, v16
162 ; CHECK-NEXT: vadd.vv v8, v8, v24
163 ; CHECK-NEXT: vadd.vx v8, v8, a1
165 %r = add <32 x i32> %x, %y
166 %s = add <32 x i32> %r, %z
167 %head = insertelement <32 x i32> poison, i32 %w, i32 0
168 %splat = shufflevector <32 x i32> %head, <32 x i32> poison, <32 x i32> zeroinitializer
169 %t = add <32 x i32> %s, %splat
173 declare <32 x i32> @ext2(<32 x i32>, <32 x i32>, i32, i32)
174 declare <32 x i32> @ext3(<32 x i32>, <32 x i32>, <32 x i32>, i32, i32)
176 define <32 x i32> @ret_v32i32_call_v32i32_v32i32_i32(<32 x i32> %x, <32 x i32> %y, i32 %w) {
177 ; CHECK-LABEL: ret_v32i32_call_v32i32_v32i32_i32:
179 ; CHECK-NEXT: addi sp, sp, -16
180 ; CHECK-NEXT: .cfi_def_cfa_offset 16
181 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
182 ; CHECK-NEXT: .cfi_offset ra, -8
183 ; CHECK-NEXT: vmv8r.v v24, v8
184 ; CHECK-NEXT: li a1, 2
185 ; CHECK-NEXT: vmv8r.v v8, v16
186 ; CHECK-NEXT: vmv8r.v v16, v24
187 ; CHECK-NEXT: call ext2
188 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
189 ; CHECK-NEXT: addi sp, sp, 16
191 %t = call <32 x i32> @ext2(<32 x i32> %y, <32 x i32> %x, i32 %w, i32 2)
195 define <32 x i32> @ret_v32i32_call_v32i32_v32i32_v32i32_i32(<32 x i32> %x, <32 x i32> %y, <32 x i32> %z, i32 %w) {
196 ; CHECK-LABEL: ret_v32i32_call_v32i32_v32i32_v32i32_i32:
198 ; CHECK-NEXT: addi sp, sp, -256
199 ; CHECK-NEXT: .cfi_def_cfa_offset 256
200 ; CHECK-NEXT: sd ra, 248(sp) # 8-byte Folded Spill
201 ; CHECK-NEXT: sd s0, 240(sp) # 8-byte Folded Spill
202 ; CHECK-NEXT: .cfi_offset ra, -8
203 ; CHECK-NEXT: .cfi_offset s0, -16
204 ; CHECK-NEXT: addi s0, sp, 256
205 ; CHECK-NEXT: .cfi_def_cfa s0, 0
206 ; CHECK-NEXT: andi sp, sp, -128
207 ; CHECK-NEXT: li a2, 32
208 ; CHECK-NEXT: vsetvli zero, a2, e32, m8, ta, ma
209 ; CHECK-NEXT: vle32.v v24, (a0)
210 ; CHECK-NEXT: mv a3, sp
211 ; CHECK-NEXT: mv a0, sp
212 ; CHECK-NEXT: li a2, 42
213 ; CHECK-NEXT: vse32.v v8, (a3)
214 ; CHECK-NEXT: vmv.v.v v8, v24
215 ; CHECK-NEXT: call ext3
216 ; CHECK-NEXT: addi sp, s0, -256
217 ; CHECK-NEXT: ld ra, 248(sp) # 8-byte Folded Reload
218 ; CHECK-NEXT: ld s0, 240(sp) # 8-byte Folded Reload
219 ; CHECK-NEXT: addi sp, sp, 256
221 %t = call <32 x i32> @ext3(<32 x i32> %z, <32 x i32> %y, <32 x i32> %x, i32 %w, i32 42)
225 ; Test various configurations of split vector types where the values are split
226 ; across both registers and the stack.
228 ; v20m2 y[24:31], v22m2 z[0:7], a1+0 z[8:15], a1+32 z[16:23],
230 ; v16 y[12:15], v17 y[16:19], v18 y[20:23], v19 y[24:27],
231 ; v20 y[28:31], v21 z[0:3], v22 z[4:7], v23 z[8:11],
232 ; a1+0 z[12:15], a1+16 z[16:19], a1+32 z[20:23], a1+48 z[24:27],
234 define <32 x i32> @split_vector_args(<2 x i32>,<2 x i32>,<2 x i32>,<2 x i32>,<2 x i32>, <32 x i32> %y, <32 x i32> %z) {
235 ; CHECK-LABEL: split_vector_args:
237 ; CHECK-NEXT: li a1, 32
238 ; CHECK-NEXT: vsetvli zero, a1, e32, m8, ta, ma
239 ; CHECK-NEXT: vle32.v v8, (a0)
240 ; CHECK-NEXT: vadd.vv v8, v16, v8
242 %v0 = add <32 x i32> %y, %z
246 define <32 x i32> @call_split_vector_args(ptr %pa, ptr %pb) {
247 ; CHECK-LABEL: call_split_vector_args:
249 ; CHECK-NEXT: addi sp, sp, -256
250 ; CHECK-NEXT: .cfi_def_cfa_offset 256
251 ; CHECK-NEXT: sd ra, 248(sp) # 8-byte Folded Spill
252 ; CHECK-NEXT: sd s0, 240(sp) # 8-byte Folded Spill
253 ; CHECK-NEXT: .cfi_offset ra, -8
254 ; CHECK-NEXT: .cfi_offset s0, -16
255 ; CHECK-NEXT: addi s0, sp, 256
256 ; CHECK-NEXT: .cfi_def_cfa s0, 0
257 ; CHECK-NEXT: andi sp, sp, -128
258 ; CHECK-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
259 ; CHECK-NEXT: vle32.v v8, (a0)
260 ; CHECK-NEXT: li a0, 32
261 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
262 ; CHECK-NEXT: vle32.v v16, (a1)
263 ; CHECK-NEXT: mv a1, sp
264 ; CHECK-NEXT: mv a0, sp
265 ; CHECK-NEXT: vse32.v v16, (a1)
266 ; CHECK-NEXT: vmv1r.v v9, v8
267 ; CHECK-NEXT: vmv1r.v v10, v8
268 ; CHECK-NEXT: vmv1r.v v11, v8
269 ; CHECK-NEXT: vmv1r.v v12, v8
270 ; CHECK-NEXT: call split_vector_args
271 ; CHECK-NEXT: addi sp, s0, -256
272 ; CHECK-NEXT: ld ra, 248(sp) # 8-byte Folded Reload
273 ; CHECK-NEXT: ld s0, 240(sp) # 8-byte Folded Reload
274 ; CHECK-NEXT: addi sp, sp, 256
276 %a = load <2 x i32>, ptr %pa
277 %b = load <32 x i32>, ptr %pb
278 %r = call <32 x i32> @split_vector_args(<2 x i32> %a, <2 x i32> %a, <2 x i32> %a, <2 x i32> %a, <2 x i32> %a, <32 x i32> %b, <32 x i32> %b)
282 ; A rather pathological test case in which we exhaust all vector registers and
283 ; all scalar registers, forcing %z and %8 to go through the stack.
284 define <32 x i32> @vector_arg_via_stack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, <32 x i32> %x, <32 x i32> %y, <32 x i32> %z, i32 %8) {
285 ; CHECK-LABEL: vector_arg_via_stack:
287 ; CHECK-NEXT: li a0, 32
288 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
289 ; CHECK-NEXT: vle32.v v16, (sp)
290 ; CHECK-NEXT: vadd.vv v8, v8, v16
292 %s = add <32 x i32> %x, %z
296 ; Calling the function above. Ensure we pass the arguments correctly.
297 define <32 x i32> @pass_vector_arg_via_stack(<32 x i32> %x, <32 x i32> %y, <32 x i32> %z) {
298 ; CHECK-LABEL: pass_vector_arg_via_stack:
300 ; CHECK-NEXT: addi sp, sp, -144
301 ; CHECK-NEXT: .cfi_def_cfa_offset 144
302 ; CHECK-NEXT: sd ra, 136(sp) # 8-byte Folded Spill
303 ; CHECK-NEXT: .cfi_offset ra, -8
304 ; CHECK-NEXT: li a0, 32
305 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
306 ; CHECK-NEXT: vmv.v.i v8, 0
307 ; CHECK-NEXT: vse32.v v8, (sp)
308 ; CHECK-NEXT: li a0, 8
309 ; CHECK-NEXT: li a1, 1
310 ; CHECK-NEXT: li a2, 2
311 ; CHECK-NEXT: li a3, 3
312 ; CHECK-NEXT: li a4, 4
313 ; CHECK-NEXT: li a5, 5
314 ; CHECK-NEXT: li a6, 6
315 ; CHECK-NEXT: li a7, 7
316 ; CHECK-NEXT: sd a0, 128(sp)
317 ; CHECK-NEXT: li a0, 0
318 ; CHECK-NEXT: vmv.v.i v16, 0
319 ; CHECK-NEXT: call vector_arg_via_stack
320 ; CHECK-NEXT: ld ra, 136(sp) # 8-byte Folded Reload
321 ; CHECK-NEXT: addi sp, sp, 144
323 %s = call <32 x i32> @vector_arg_via_stack(i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, i32 8)
327 ; Another pathological case but where a small mask vector must be passed on the
329 define <4 x i1> @vector_mask_arg_via_stack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, <32 x i32> %x, <32 x i32> %y, <32 x i32> %z, i32 %8, <4 x i1> %9, <4 x i1> %10) {
330 ; CHECK-LABEL: vector_mask_arg_via_stack:
332 ; CHECK-NEXT: addi a0, sp, 136
333 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
334 ; CHECK-NEXT: vlm.v v0, (a0)
339 ; Calling the function above. Ensure we pass the mask arguments correctly. We
340 ; legalize stores of small masks such that the value is at least byte-sized.
341 define <4 x i1> @pass_vector_mask_arg_via_stack(<4 x i1> %v) {
342 ; CHECK-LABEL: pass_vector_mask_arg_via_stack:
344 ; CHECK-NEXT: addi sp, sp, -160
345 ; CHECK-NEXT: .cfi_def_cfa_offset 160
346 ; CHECK-NEXT: sd ra, 152(sp) # 8-byte Folded Spill
347 ; CHECK-NEXT: .cfi_offset ra, -8
348 ; CHECK-NEXT: li a0, 32
349 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
350 ; CHECK-NEXT: vmv.v.i v8, 0
351 ; CHECK-NEXT: vse32.v v8, (sp)
352 ; CHECK-NEXT: li a0, 8
353 ; CHECK-NEXT: sd a0, 128(sp)
354 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
355 ; CHECK-NEXT: vmv.v.i v16, 0
356 ; CHECK-NEXT: vmerge.vim v16, v16, 1, v0
357 ; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
358 ; CHECK-NEXT: vmv.v.i v17, 0
359 ; CHECK-NEXT: vsetivli zero, 4, e8, mf2, tu, ma
360 ; CHECK-NEXT: vmv.v.v v17, v16
361 ; CHECK-NEXT: vsetivli zero, 8, e8, mf2, ta, ma
362 ; CHECK-NEXT: vmsne.vi v16, v17, 0
363 ; CHECK-NEXT: addi a0, sp, 136
364 ; CHECK-NEXT: li a5, 5
365 ; CHECK-NEXT: li a6, 6
366 ; CHECK-NEXT: li a7, 7
367 ; CHECK-NEXT: vsm.v v16, (a0)
368 ; CHECK-NEXT: li a0, 0
369 ; CHECK-NEXT: li a1, 0
370 ; CHECK-NEXT: li a2, 0
371 ; CHECK-NEXT: li a3, 0
372 ; CHECK-NEXT: li a4, 0
373 ; CHECK-NEXT: vmv8r.v v16, v8
374 ; CHECK-NEXT: call vector_mask_arg_via_stack
375 ; CHECK-NEXT: ld ra, 152(sp) # 8-byte Folded Reload
376 ; CHECK-NEXT: addi sp, sp, 160
378 %r = call <4 x i1> @vector_mask_arg_via_stack(i32 0, i32 0, i32 0, i32 0, i32 0, i32 5, i32 6, i32 7, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, i32 8, <4 x i1> %v, <4 x i1> %v)