1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch64 --target-abi=lp64s < %s | FileCheck %s
3 ; RUN: llc --mtriple=loongarch64 --mattr=+d --target-abi=lp64d < %s | FileCheck %s
5 ;; This file contains tests that should have identical output for all ABIs, i.e.
6 ;; where no arguments are passed via floating point registers.
8 ;; Check that on LA64, i128 is passed in a pair of GPRs.
9 define i64 @callee_i128_in_regs(i64 %a, i128 %b) nounwind {
10 ; CHECK-LABEL: callee_i128_in_regs:
12 ; CHECK-NEXT: add.d $a0, $a0, $a1
14 %b_trunc = trunc i128 %b to i64
15 %1 = add i64 %a, %b_trunc
19 define i64 @caller_i128_in_regs() nounwind {
20 ; CHECK-LABEL: caller_i128_in_regs:
22 ; CHECK-NEXT: addi.d $sp, $sp, -16
23 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
24 ; CHECK-NEXT: ori $a0, $zero, 1
25 ; CHECK-NEXT: ori $a1, $zero, 2
26 ; CHECK-NEXT: move $a2, $zero
27 ; CHECK-NEXT: bl %plt(callee_i128_in_regs)
28 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
29 ; CHECK-NEXT: addi.d $sp, $sp, 16
31 %1 = call i64 @callee_i128_in_regs(i64 1, i128 2)
35 ;; Check that the stack is used once the GPRs are exhausted.
36 define i64 @callee_many_scalars(i8 %a, i16 %b, i32 %c, i64 %d, i128 %e, i64 %f, i128 %g, i64 %h) nounwind {
37 ; CHECK-LABEL: callee_many_scalars:
39 ; CHECK-NEXT: ld.d $t0, $sp, 8
40 ; CHECK-NEXT: ld.d $t1, $sp, 0
41 ; CHECK-NEXT: andi $a0, $a0, 255
42 ; CHECK-NEXT: bstrpick.d $a1, $a1, 15, 0
43 ; CHECK-NEXT: bstrpick.d $a2, $a2, 31, 0
44 ; CHECK-NEXT: add.d $a0, $a0, $a1
45 ; CHECK-NEXT: add.d $a0, $a0, $a2
46 ; CHECK-NEXT: add.d $a0, $a0, $a3
47 ; CHECK-NEXT: xor $a1, $a5, $t1
48 ; CHECK-NEXT: xor $a2, $a4, $a7
49 ; CHECK-NEXT: or $a1, $a2, $a1
50 ; CHECK-NEXT: sltui $a1, $a1, 1
51 ; CHECK-NEXT: add.d $a0, $a1, $a0
52 ; CHECK-NEXT: add.d $a0, $a0, $a6
53 ; CHECK-NEXT: add.d $a0, $a0, $t0
55 %a_ext = zext i8 %a to i64
56 %b_ext = zext i16 %b to i64
57 %c_ext = zext i32 %c to i64
58 %1 = add i64 %a_ext, %b_ext
59 %2 = add i64 %1, %c_ext
61 %4 = icmp eq i128 %e, %g
62 %5 = zext i1 %4 to i64
69 define i64 @caller_many_scalars() nounwind {
70 ; CHECK-LABEL: caller_many_scalars:
72 ; CHECK-NEXT: addi.d $sp, $sp, -32
73 ; CHECK-NEXT: st.d $ra, $sp, 24 # 8-byte Folded Spill
74 ; CHECK-NEXT: ori $a0, $zero, 8
75 ; CHECK-NEXT: st.d $a0, $sp, 8
76 ; CHECK-NEXT: ori $a0, $zero, 1
77 ; CHECK-NEXT: ori $a1, $zero, 2
78 ; CHECK-NEXT: ori $a2, $zero, 3
79 ; CHECK-NEXT: ori $a3, $zero, 4
80 ; CHECK-NEXT: ori $a4, $zero, 5
81 ; CHECK-NEXT: ori $a6, $zero, 6
82 ; CHECK-NEXT: ori $a7, $zero, 7
83 ; CHECK-NEXT: st.d $zero, $sp, 0
84 ; CHECK-NEXT: move $a5, $zero
85 ; CHECK-NEXT: bl %plt(callee_many_scalars)
86 ; CHECK-NEXT: ld.d $ra, $sp, 24 # 8-byte Folded Reload
87 ; CHECK-NEXT: addi.d $sp, $sp, 32
89 %1 = call i64 @callee_many_scalars(i8 1, i16 2, i32 3, i64 4, i128 5, i64 6, i128 7, i64 8)
93 ;; Check that i256 is passed indirectly.
95 define i64 @callee_large_scalars(i256 %a, i256 %b) nounwind {
96 ; CHECK-LABEL: callee_large_scalars:
98 ; CHECK-NEXT: ld.d $a2, $a1, 0
99 ; CHECK-NEXT: ld.d $a3, $a0, 0
100 ; CHECK-NEXT: ld.d $a4, $a1, 8
101 ; CHECK-NEXT: ld.d $a5, $a1, 24
102 ; CHECK-NEXT: ld.d $a6, $a0, 24
103 ; CHECK-NEXT: ld.d $a7, $a0, 8
104 ; CHECK-NEXT: ld.d $a1, $a1, 16
105 ; CHECK-NEXT: ld.d $a0, $a0, 16
106 ; CHECK-NEXT: xor $a5, $a6, $a5
107 ; CHECK-NEXT: xor $a4, $a7, $a4
108 ; CHECK-NEXT: or $a4, $a4, $a5
109 ; CHECK-NEXT: xor $a0, $a0, $a1
110 ; CHECK-NEXT: xor $a1, $a3, $a2
111 ; CHECK-NEXT: or $a0, $a1, $a0
112 ; CHECK-NEXT: or $a0, $a0, $a4
113 ; CHECK-NEXT: sltui $a0, $a0, 1
115 %1 = icmp eq i256 %a, %b
116 %2 = zext i1 %1 to i64
120 define i64 @caller_large_scalars() nounwind {
121 ; CHECK-LABEL: caller_large_scalars:
123 ; CHECK-NEXT: addi.d $sp, $sp, -80
124 ; CHECK-NEXT: st.d $ra, $sp, 72 # 8-byte Folded Spill
125 ; CHECK-NEXT: st.d $zero, $sp, 24
126 ; CHECK-NEXT: st.d $zero, $sp, 16
127 ; CHECK-NEXT: st.d $zero, $sp, 8
128 ; CHECK-NEXT: ori $a0, $zero, 2
129 ; CHECK-NEXT: st.d $a0, $sp, 0
130 ; CHECK-NEXT: st.d $zero, $sp, 56
131 ; CHECK-NEXT: st.d $zero, $sp, 48
132 ; CHECK-NEXT: st.d $zero, $sp, 40
133 ; CHECK-NEXT: ori $a2, $zero, 1
134 ; CHECK-NEXT: addi.d $a0, $sp, 32
135 ; CHECK-NEXT: addi.d $a1, $sp, 0
136 ; CHECK-NEXT: st.d $a2, $sp, 32
137 ; CHECK-NEXT: bl %plt(callee_large_scalars)
138 ; CHECK-NEXT: ld.d $ra, $sp, 72 # 8-byte Folded Reload
139 ; CHECK-NEXT: addi.d $sp, $sp, 80
141 %1 = call i64 @callee_large_scalars(i256 1, i256 2)
145 ;; Check that arguments larger than 2*GRLen are handled correctly when their
146 ;; address is passed on the stack rather than in memory.
148 ;; Must keep define on a single line due to an update_llc_test_checks.py limitation
149 define i64 @callee_large_scalars_exhausted_regs(i64 %a, i64 %b, i64 %c, i64 %d, i64 %e, i64 %f, i64 %g, i256 %h, i64 %i, i256 %j) nounwind {
150 ; CHECK-LABEL: callee_large_scalars_exhausted_regs:
152 ; CHECK-NEXT: ld.d $a0, $sp, 8
153 ; CHECK-NEXT: ld.d $a1, $a0, 0
154 ; CHECK-NEXT: ld.d $a2, $a7, 0
155 ; CHECK-NEXT: ld.d $a3, $a0, 8
156 ; CHECK-NEXT: ld.d $a4, $a0, 24
157 ; CHECK-NEXT: ld.d $a5, $a7, 24
158 ; CHECK-NEXT: ld.d $a6, $a7, 8
159 ; CHECK-NEXT: ld.d $a0, $a0, 16
160 ; CHECK-NEXT: ld.d $a7, $a7, 16
161 ; CHECK-NEXT: xor $a4, $a5, $a4
162 ; CHECK-NEXT: xor $a3, $a6, $a3
163 ; CHECK-NEXT: or $a3, $a3, $a4
164 ; CHECK-NEXT: xor $a0, $a7, $a0
165 ; CHECK-NEXT: xor $a1, $a2, $a1
166 ; CHECK-NEXT: or $a0, $a1, $a0
167 ; CHECK-NEXT: or $a0, $a0, $a3
168 ; CHECK-NEXT: sltui $a0, $a0, 1
170 %1 = icmp eq i256 %h, %j
171 %2 = zext i1 %1 to i64
175 define i64 @caller_large_scalars_exhausted_regs() nounwind {
176 ; CHECK-LABEL: caller_large_scalars_exhausted_regs:
178 ; CHECK-NEXT: addi.d $sp, $sp, -96
179 ; CHECK-NEXT: st.d $ra, $sp, 88 # 8-byte Folded Spill
180 ; CHECK-NEXT: addi.d $a0, $sp, 16
181 ; CHECK-NEXT: st.d $a0, $sp, 8
182 ; CHECK-NEXT: ori $a0, $zero, 9
183 ; CHECK-NEXT: st.d $a0, $sp, 0
184 ; CHECK-NEXT: st.d $zero, $sp, 40
185 ; CHECK-NEXT: st.d $zero, $sp, 32
186 ; CHECK-NEXT: st.d $zero, $sp, 24
187 ; CHECK-NEXT: ori $a0, $zero, 10
188 ; CHECK-NEXT: st.d $a0, $sp, 16
189 ; CHECK-NEXT: st.d $zero, $sp, 72
190 ; CHECK-NEXT: st.d $zero, $sp, 64
191 ; CHECK-NEXT: st.d $zero, $sp, 56
192 ; CHECK-NEXT: ori $t0, $zero, 8
193 ; CHECK-NEXT: ori $a0, $zero, 1
194 ; CHECK-NEXT: ori $a1, $zero, 2
195 ; CHECK-NEXT: ori $a2, $zero, 3
196 ; CHECK-NEXT: ori $a3, $zero, 4
197 ; CHECK-NEXT: ori $a4, $zero, 5
198 ; CHECK-NEXT: ori $a5, $zero, 6
199 ; CHECK-NEXT: ori $a6, $zero, 7
200 ; CHECK-NEXT: addi.d $a7, $sp, 48
201 ; CHECK-NEXT: st.d $t0, $sp, 48
202 ; CHECK-NEXT: bl %plt(callee_large_scalars_exhausted_regs)
203 ; CHECK-NEXT: ld.d $ra, $sp, 88 # 8-byte Folded Reload
204 ; CHECK-NEXT: addi.d $sp, $sp, 96
206 %1 = call i64 @callee_large_scalars_exhausted_regs(
207 i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i256 8, i64 9,
212 ;; Check large struct arguments, which are passed byval
214 %struct.large = type { i64, i64, i64, i64 }
216 define i64 @callee_large_struct(ptr byval(%struct.large) align 8 %a) nounwind {
217 ; CHECK-LABEL: callee_large_struct:
219 ; CHECK-NEXT: ld.d $a1, $a0, 0
220 ; CHECK-NEXT: ld.d $a0, $a0, 24
221 ; CHECK-NEXT: add.d $a0, $a1, $a0
223 %1 = getelementptr inbounds %struct.large, ptr %a, i64 0, i32 0
224 %2 = getelementptr inbounds %struct.large, ptr %a, i64 0, i32 3
225 %3 = load i64, ptr %1
226 %4 = load i64, ptr %2
231 define i64 @caller_large_struct() nounwind {
232 ; CHECK-LABEL: caller_large_struct:
234 ; CHECK-NEXT: addi.d $sp, $sp, -80
235 ; CHECK-NEXT: st.d $ra, $sp, 72 # 8-byte Folded Spill
236 ; CHECK-NEXT: ori $a0, $zero, 1
237 ; CHECK-NEXT: st.d $a0, $sp, 40
238 ; CHECK-NEXT: ori $a1, $zero, 2
239 ; CHECK-NEXT: st.d $a1, $sp, 48
240 ; CHECK-NEXT: ori $a2, $zero, 3
241 ; CHECK-NEXT: st.d $a2, $sp, 56
242 ; CHECK-NEXT: ori $a3, $zero, 4
243 ; CHECK-NEXT: st.d $a3, $sp, 64
244 ; CHECK-NEXT: st.d $a0, $sp, 8
245 ; CHECK-NEXT: st.d $a1, $sp, 16
246 ; CHECK-NEXT: st.d $a2, $sp, 24
247 ; CHECK-NEXT: st.d $a3, $sp, 32
248 ; CHECK-NEXT: addi.d $a0, $sp, 8
249 ; CHECK-NEXT: bl %plt(callee_large_struct)
250 ; CHECK-NEXT: ld.d $ra, $sp, 72 # 8-byte Folded Reload
251 ; CHECK-NEXT: addi.d $sp, $sp, 80
253 %ls = alloca %struct.large, align 8
254 %a = getelementptr inbounds %struct.large, ptr %ls, i64 0, i32 0
256 %b = getelementptr inbounds %struct.large, ptr %ls, i64 0, i32 1
258 %c = getelementptr inbounds %struct.large, ptr %ls, i64 0, i32 2
260 %d = getelementptr inbounds %struct.large, ptr %ls, i64 0, i32 3
262 %1 = call i64 @callee_large_struct(ptr byval(%struct.large) align 8 %ls)
266 ;; Check return scalar which size is 2*GRLen.
268 define i128 @callee_small_scalar_ret() nounwind {
269 ; CHECK-LABEL: callee_small_scalar_ret:
271 ; CHECK-NEXT: addi.w $a0, $zero, -1
272 ; CHECK-NEXT: move $a1, $a0
277 define i64 @caller_small_scalar_ret() nounwind {
278 ; CHECK-LABEL: caller_small_scalar_ret:
280 ; CHECK-NEXT: addi.d $sp, $sp, -16
281 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
282 ; CHECK-NEXT: bl %plt(callee_small_scalar_ret)
283 ; CHECK-NEXT: addi.w $a2, $zero, -2
284 ; CHECK-NEXT: xor $a0, $a0, $a2
285 ; CHECK-NEXT: orn $a0, $a0, $a1
286 ; CHECK-NEXT: sltui $a0, $a0, 1
287 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
288 ; CHECK-NEXT: addi.d $sp, $sp, 16
290 %1 = call i128 @callee_small_scalar_ret()
291 %2 = icmp eq i128 -2, %1
292 %3 = zext i1 %2 to i64
296 ;; Check return struct which size is 2*GRLen.
298 %struct.small = type { i64, ptr }
300 define %struct.small @callee_small_struct_ret() nounwind {
301 ; CHECK-LABEL: callee_small_struct_ret:
303 ; CHECK-NEXT: ori $a0, $zero, 1
304 ; CHECK-NEXT: move $a1, $zero
306 ret %struct.small { i64 1, ptr null }
309 define i64 @caller_small_struct_ret() nounwind {
310 ; CHECK-LABEL: caller_small_struct_ret:
312 ; CHECK-NEXT: addi.d $sp, $sp, -16
313 ; CHECK-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
314 ; CHECK-NEXT: bl %plt(callee_small_struct_ret)
315 ; CHECK-NEXT: add.d $a0, $a0, $a1
316 ; CHECK-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
317 ; CHECK-NEXT: addi.d $sp, $sp, 16
319 %1 = call %struct.small @callee_small_struct_ret()
320 %2 = extractvalue %struct.small %1, 0
321 %3 = extractvalue %struct.small %1, 1
322 %4 = ptrtoint ptr %3 to i64
327 ;; Check return scalar which size is more than 2*GRLen.
329 define i256 @callee_large_scalar_ret() nounwind {
330 ; CHECK-LABEL: callee_large_scalar_ret:
332 ; CHECK-NEXT: addi.w $a1, $zero, -1
333 ; CHECK-NEXT: st.d $a1, $a0, 24
334 ; CHECK-NEXT: st.d $a1, $a0, 16
335 ; CHECK-NEXT: st.d $a1, $a0, 8
336 ; CHECK-NEXT: lu12i.w $a1, -30141
337 ; CHECK-NEXT: ori $a1, $a1, 747
338 ; CHECK-NEXT: st.d $a1, $a0, 0
343 define void @caller_large_scalar_ret() nounwind {
344 ; CHECK-LABEL: caller_large_scalar_ret:
346 ; CHECK-NEXT: addi.d $sp, $sp, -48
347 ; CHECK-NEXT: st.d $ra, $sp, 40 # 8-byte Folded Spill
348 ; CHECK-NEXT: addi.d $a0, $sp, 0
349 ; CHECK-NEXT: bl %plt(callee_large_scalar_ret)
350 ; CHECK-NEXT: ld.d $ra, $sp, 40 # 8-byte Folded Reload
351 ; CHECK-NEXT: addi.d $sp, $sp, 48
353 %1 = call i256 @callee_large_scalar_ret()
357 ;; Check return struct which size is more than 2*GRLen.
359 define void @callee_large_struct_ret(ptr noalias sret(%struct.large) %agg.result) nounwind {
360 ; CHECK-LABEL: callee_large_struct_ret:
362 ; CHECK-NEXT: ori $a1, $zero, 1
363 ; CHECK-NEXT: st.d $a1, $a0, 0
364 ; CHECK-NEXT: ori $a1, $zero, 2
365 ; CHECK-NEXT: st.d $a1, $a0, 8
366 ; CHECK-NEXT: ori $a1, $zero, 3
367 ; CHECK-NEXT: st.d $a1, $a0, 16
368 ; CHECK-NEXT: ori $a1, $zero, 4
369 ; CHECK-NEXT: st.d $a1, $a0, 24
371 %a = getelementptr inbounds %struct.large, ptr %agg.result, i64 0, i32 0
372 store i64 1, ptr %a, align 4
373 %b = getelementptr inbounds %struct.large, ptr %agg.result, i64 0, i32 1
374 store i64 2, ptr %b, align 4
375 %c = getelementptr inbounds %struct.large, ptr %agg.result, i64 0, i32 2
376 store i64 3, ptr %c, align 4
377 %d = getelementptr inbounds %struct.large, ptr %agg.result, i64 0, i32 3
378 store i64 4, ptr %d, align 4
382 define i64 @caller_large_struct_ret() nounwind {
383 ; CHECK-LABEL: caller_large_struct_ret:
385 ; CHECK-NEXT: addi.d $sp, $sp, -48
386 ; CHECK-NEXT: st.d $ra, $sp, 40 # 8-byte Folded Spill
387 ; CHECK-NEXT: addi.d $a0, $sp, 8
388 ; CHECK-NEXT: bl %plt(callee_large_struct_ret)
389 ; CHECK-NEXT: ld.d $a0, $sp, 8
390 ; CHECK-NEXT: ld.d $a1, $sp, 32
391 ; CHECK-NEXT: add.d $a0, $a0, $a1
392 ; CHECK-NEXT: ld.d $ra, $sp, 40 # 8-byte Folded Reload
393 ; CHECK-NEXT: addi.d $sp, $sp, 48
395 %1 = alloca %struct.large
396 call void @callee_large_struct_ret(ptr sret(%struct.large) %1)
397 %2 = getelementptr inbounds %struct.large, ptr %1, i64 0, i32 0
398 %3 = load i64, ptr %2
399 %4 = getelementptr inbounds %struct.large, ptr %1, i64 0, i32 3
400 %5 = load i64, ptr %4