1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s | FileCheck %s
4 define fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <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 fastcc <32 x i32> @ext2(<32 x i32> %y, <32 x i32> %x, i32 %w, i32 2)
195 define fastcc <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 fastcc <32 x i32> @ext3(<32 x i32> %z, <32 x i32> %y, <32 x i32> %x, i32 %w, i32 42)
225 ; A test case where the normal calling convention would pass directly via the
226 ; stack, but with fastcc can pass indirectly with the extra GPR registers
228 define fastcc <32 x i32> @vector_arg_indirect_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) {
229 ; CHECK-LABEL: vector_arg_indirect_stack:
231 ; CHECK-NEXT: li a0, 32
232 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
233 ; CHECK-NEXT: vle32.v v16, (t3)
234 ; CHECK-NEXT: vadd.vv v8, v8, v16
236 %s = add <32 x i32> %x, %z
240 ; Calling the function above. Ensure we pass the arguments correctly.
241 define fastcc <32 x i32> @pass_vector_arg_indirect_stack(<32 x i32> %x, <32 x i32> %y, <32 x i32> %z) {
242 ; CHECK-LABEL: pass_vector_arg_indirect_stack:
244 ; CHECK-NEXT: addi sp, sp, -256
245 ; CHECK-NEXT: .cfi_def_cfa_offset 256
246 ; CHECK-NEXT: sd ra, 248(sp) # 8-byte Folded Spill
247 ; CHECK-NEXT: sd s0, 240(sp) # 8-byte Folded Spill
248 ; CHECK-NEXT: .cfi_offset ra, -8
249 ; CHECK-NEXT: .cfi_offset s0, -16
250 ; CHECK-NEXT: addi s0, sp, 256
251 ; CHECK-NEXT: .cfi_def_cfa s0, 0
252 ; CHECK-NEXT: andi sp, sp, -128
253 ; CHECK-NEXT: li a0, 32
254 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
255 ; CHECK-NEXT: vmv.v.i v8, 0
256 ; CHECK-NEXT: mv a0, sp
257 ; CHECK-NEXT: li a1, 1
258 ; CHECK-NEXT: li a2, 2
259 ; CHECK-NEXT: li a3, 3
260 ; CHECK-NEXT: li a4, 4
261 ; CHECK-NEXT: li a5, 5
262 ; CHECK-NEXT: li a6, 6
263 ; CHECK-NEXT: li a7, 7
264 ; CHECK-NEXT: mv t3, sp
265 ; CHECK-NEXT: li t4, 8
266 ; CHECK-NEXT: vse32.v v8, (a0)
267 ; CHECK-NEXT: li a0, 0
268 ; CHECK-NEXT: vmv.v.i v16, 0
269 ; CHECK-NEXT: call vector_arg_indirect_stack
270 ; CHECK-NEXT: addi sp, s0, -256
271 ; CHECK-NEXT: ld ra, 248(sp) # 8-byte Folded Reload
272 ; CHECK-NEXT: ld s0, 240(sp) # 8-byte Folded Reload
273 ; CHECK-NEXT: addi sp, sp, 256
275 %s = call fastcc <32 x i32> @vector_arg_indirect_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)
279 ; A pathological test case where even with fastcc we must use the stack for arguments %13 and %z
280 define fastcc <32 x i32> @vector_arg_direct_stack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, <32 x i32> %x, <32 x i32> %y, <32 x i32> %z, i32 %last) {
281 ; CHECK-LABEL: vector_arg_direct_stack:
283 ; CHECK-NEXT: li a0, 32
284 ; CHECK-NEXT: addi a1, sp, 16
285 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
286 ; CHECK-NEXT: vle32.v v24, (a1)
287 ; CHECK-NEXT: vadd.vv v8, v8, v16
288 ; CHECK-NEXT: vadd.vv v8, v8, v24
290 %s = add <32 x i32> %x, %y
291 %t = add <32 x i32> %s, %z
295 ; Calling the function above. Ensure we pass the arguments correctly.
296 define fastcc <32 x i32> @pass_vector_arg_direct_stack(<32 x i32> %x, <32 x i32> %y, <32 x i32> %z) {
297 ; CHECK-LABEL: pass_vector_arg_direct_stack:
299 ; CHECK-NEXT: addi sp, sp, -160
300 ; CHECK-NEXT: .cfi_def_cfa_offset 160
301 ; CHECK-NEXT: sd ra, 152(sp) # 8-byte Folded Spill
302 ; CHECK-NEXT: .cfi_offset ra, -8
303 ; CHECK-NEXT: li a0, 32
304 ; CHECK-NEXT: vsetvli zero, a0, e32, m8, ta, ma
305 ; CHECK-NEXT: vmv.v.i v8, 0
306 ; CHECK-NEXT: addi a0, sp, 16
307 ; CHECK-NEXT: vse32.v v8, (a0)
308 ; CHECK-NEXT: li a0, 1
309 ; CHECK-NEXT: sd a0, 144(sp)
310 ; CHECK-NEXT: li a0, 13
311 ; CHECK-NEXT: sd a0, 8(sp)
312 ; CHECK-NEXT: li a0, 12
313 ; CHECK-NEXT: li a1, 1
314 ; CHECK-NEXT: li a2, 2
315 ; CHECK-NEXT: li a3, 3
316 ; CHECK-NEXT: li a4, 4
317 ; CHECK-NEXT: li a5, 5
318 ; CHECK-NEXT: li a6, 6
319 ; CHECK-NEXT: li a7, 7
320 ; CHECK-NEXT: li t3, 8
321 ; CHECK-NEXT: li t4, 9
322 ; CHECK-NEXT: li t5, 10
323 ; CHECK-NEXT: li t6, 11
324 ; CHECK-NEXT: sd a0, 0(sp)
325 ; CHECK-NEXT: li a0, 0
326 ; CHECK-NEXT: vmv.v.i v16, 0
327 ; CHECK-NEXT: call vector_arg_direct_stack
328 ; CHECK-NEXT: ld ra, 152(sp) # 8-byte Folded Reload
329 ; CHECK-NEXT: addi sp, sp, 160
331 %s = call fastcc <32 x i32> @vector_arg_direct_stack(i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, <32 x i32> zeroinitializer, i32 1)
335 ; A pathological test case where even with fastcc we must use the stack for
336 ; mask argument %m2. %m1 is passed via v0.
337 define fastcc <4 x i1> @vector_mask_arg_direct_stack(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12, i32 %13, <32 x i32> %x, <32 x i32> %y, <32 x i32> %z, <4 x i1> %m1, <4 x i1> %m2, i32 %last) {
338 ; CHECK-LABEL: vector_mask_arg_direct_stack:
340 ; CHECK-NEXT: addi a0, sp, 144
341 ; CHECK-NEXT: vsetivli zero, 4, e8, mf4, ta, ma
342 ; CHECK-NEXT: vlm.v v8, (a0)
343 ; CHECK-NEXT: vmxor.mm v0, v0, v8
345 %r = xor <4 x i1> %m1, %m2