1 ; RUN: llc < %s -march=sparcv9 -disable-sparc-delay-filler -disable-sparc-leaf-proc | FileCheck %s --check-prefix=CHECK --check-prefix=HARD
2 ; RUN: llc < %s -march=sparcv9 -disable-sparc-delay-filler -disable-sparc-leaf-proc -mattr=soft-float | FileCheck %s --check-prefix=CHECK --check-prefix=SOFT
5 ; The save/restore frame is not strictly necessary here, but we would need to
6 ; refer to %o registers instead.
7 ; CHECK: save %sp, -128, %sp
8 ; CHECK: ldx [%fp+2231], [[R2:%[gilo][0-7]]]
9 ; CHECK: ld [%fp+2227], [[R1:%[gilo][0-7]]]
10 ; CHECK: stb %i0, [%i4]
11 ; CHECK: stb %i1, [%i4]
12 ; CHECK: sth %i2, [%i4]
13 ; CHECK: st %i3, [%i4]
14 ; CHECK: stx %i4, [%i4]
15 ; CHECK: st %i5, [%i4]
16 ; CHECK: st [[R1]], [%i4]
17 ; CHECK: stx [[R2]], [%i4]
19 define void @intarg(i8 %a0, ; %i0
25 i32 signext %a6, ; [%fp+BIAS+176]
26 ptr %a7) { ; [%fp+BIAS+184]
27 store volatile i8 %a0, ptr %a4
28 store volatile i8 %a1, ptr %a4
29 %p16 = bitcast ptr %a4 to ptr
30 store volatile i16 %a2, ptr %p16
31 %p32 = bitcast ptr %a4 to ptr
32 store volatile i32 %a3, ptr %p32
33 %pp = bitcast ptr %a4 to ptr
34 store volatile ptr %a4, ptr %pp
35 store volatile i32 %a5, ptr %p32
36 store volatile i32 %a6, ptr %p32
37 store volatile ptr %a7, ptr %pp
41 ; CHECK-LABEL: call_intarg:
43 ; CHECK: save %sp, -192, %sp
44 ; Sign-extend and store the full 64 bits.
45 ; CHECK: sra %i0, 0, [[R:%[gilo][0-7]]]
46 ; Use %o0-%o5 for outgoing arguments
48 ; CHECK: stx [[R]], [%sp+2223]
52 define void @call_intarg(i32 %i0, ptr %i1) {
53 call void @intarg(i8 0, i8 1, i16 2, i32 3, ptr undef, i32 5, i32 signext %i0, ptr %i1)
57 ; CHECK-LABEL: floatarg:
58 ; HARD: save %sp, -128, %sp
59 ; HARD: ld [%fp+2307], [[F:%f[0-9]+]]
64 ; HARD: fadds %f31, [[F]]
65 ; SOFT: save %sp, -176, %sp
66 ; SOFT: ld [%fp+2299], %i4
67 ; SOFT: ld [%fp+2307], %i5
68 ; SOFT: srl %i0, 0, %o0
69 ; SOFT-NEXT: call __extendsfdf2
74 define double @floatarg(float %a0, ; %f1
90 float %a16, ; [%fp+BIAS+256] (using 8 bytes)
91 double %a17) { ; [%fp+BIAS+264] (using 8 bytes)
92 %d0 = fpext float %a0 to double
93 %s1 = fadd double %a1, %d0
94 %s2 = fadd double %a2, %s1
95 %s3 = fadd double %a3, %s2
96 %s16 = fadd float %a15, %a16
97 %d16 = fpext float %s16 to double
98 %s17 = fadd double %d16, %s3
102 ; CHECK-LABEL: call_floatarg:
103 ; CHECK: save %sp, -272, %sp
104 ; Store 8 bytes in full slot.
105 ; HARD: std %f2, [%sp+2311]
106 ; Store 4 bytes, right-aligned in slot.
107 ; HARD: st %f1, [%sp+2307]
108 ; HARD: fmovd %f2, %f4
109 ; SOFT: stx %i1, [%sp+2311]
110 ; SOFT: stx %i0, [%sp+2303]
111 ; SOFT: stx %i2, [%sp+2295]
112 ; SOFT: stx %i2, [%sp+2287]
113 ; SOFT: stx %i2, [%sp+2279]
114 ; SOFT: stx %i2, [%sp+2271]
115 ; SOFT: stx %i2, [%sp+2263]
116 ; SOFT: stx %i2, [%sp+2255]
117 ; SOFT: stx %i2, [%sp+2247]
118 ; SOFT: stx %i2, [%sp+2239]
119 ; SOFT: stx %i2, [%sp+2231]
120 ; SOFT: stx %i2, [%sp+2223]
127 ; CHECK: call floatarg
131 define void @call_floatarg(float %f1, double %d2, float %f5, ptr %p) {
132 %r = call double @floatarg(float %f5, double %d2, double %d2, double %d2,
133 float %f5, float %f5, float %f5, float %f5,
134 float %f5, float %f5, float %f5, float %f5,
135 float %f5, float %f5, float %f5, float %f5,
136 float %f1, double %d2)
137 store double %r, ptr %p
141 ; CHECK-LABEL: mixedarg:
142 ; CHECK: ldx [%fp+2247]
143 ; CHECK: ldx [%fp+2231]
144 ; SOFT: ldx [%fp+2239], %i0
149 ; SOFT-NEXT: mov %i3, %o0
150 ; SOFT-NEXT: call __adddf3
152 ; SOFT-NEXT: mov %i0, %o0
153 ; SOFT-NEXT: call __adddf3
154 ; HARD: std %f0, [%i1]
155 ; SOFT: stx %o0, [%i5]
157 define void @mixedarg(i8 %a0, ; %i0
163 i64 %a6, ; [%fp+BIAS+176]
164 ptr %a7, ; [%fp+BIAS+184]
166 ptr %a9) { ; [%fp+BIAS+200]
167 %d1 = fpext float %a1 to double
168 %s3 = fadd double %a3, %d1
169 %s8 = fadd double %a8, %s3
170 store double %s8, ptr %a7
171 store i16 %a2, ptr %a9
175 ; CHECK-LABEL: call_mixedarg:
176 ; CHECK: stx %i2, [%sp+2247]
177 ; SOFT: stx %i1, [%sp+2239]
178 ; CHECK: stx %i0, [%sp+2223]
179 ; HARD: fmovd %f2, %f6
180 ; HARD: fmovd %f2, %f16
182 ; CHECK: call mixedarg
186 define void @call_mixedarg(i64 %i0, double %f2, ptr %i2) {
187 call void @mixedarg(i8 undef,
200 ; The inreg attribute is used to indicate 32-bit sized struct elements that
201 ; share an 8-byte slot.
202 ; CHECK-LABEL: inreg_fi:
203 ; SOFT: srlx %i0, 32, [[R:%[gilo][0-7]]]
205 ; SOFT: call __fixsfsi
206 ; HARD: srlx %i0, 32, [[R:%[gilo][0-7]]]
208 define i32 @inreg_fi(i32 inreg %a0, ; high bits of %i0
209 float inreg %a1) { ; %f1
210 %b1 = fptosi float %a1 to i32
211 %rv = sub i32 %a0, %b1
215 ; CHECK-LABEL: call_inreg_fi:
216 ; Allocate space for 6 arguments, even when only 2 are used.
217 ; CHECK: save %sp, -176, %sp
218 ; HARD-DAG: sllx %i1, 32, %o0
219 ; HARD-DAG: fmovs %f5, %f1
220 ; SOFT: srl %i2, 0, %i0
221 ; SOFT: sllx %i1, 32, %i1
222 ; SOFT: or %i1, %i0, %o0
223 ; CHECK: call inreg_fi
224 define void @call_inreg_fi(ptr %p, i32 %i1, float %f5) {
225 %x = call i32 @inreg_fi(i32 inreg %i1, float inreg %f5)
229 ; CHECK-LABEL: inreg_ff:
230 ; HARD: fsubs %f0, %f1, %f0
231 ; SOFT: srlx %i0, 32, %o0
232 ; SOFT: srl %i0, 0, %o1
233 ; SOFT: call __subsf3
234 define float @inreg_ff(float inreg %a0, ; %f0
235 float inreg %a1) { ; %f1
236 %rv = fsub float %a0, %a1
240 ; CHECK-LABEL: call_inreg_ff:
241 ; HARD-DAG: fmovs %f3, %f0
242 ; HARD-DAG: fmovs %f5, %f1
243 ; SOFT: srl %i2, 0, %i0
244 ; SOFT: sllx %i1, 32, %i1
245 ; SOFT: or %i1, %i0, %o0
246 ; CHECK: call inreg_ff
247 define void @call_inreg_ff(ptr %p, float %f3, float %f5) {
248 %x = call float @inreg_ff(float inreg %f3, float inreg %f5)
252 ; CHECK-LABEL: inreg_if:
254 ; SOFT: srlx %i0, 32, %o0
255 ; SOFT: call __fixsfsi
257 define i32 @inreg_if(float inreg %a0, ; %f0
258 i32 inreg %a1) { ; low bits of %i0
259 %b0 = fptosi float %a0 to i32
260 %rv = sub i32 %a1, %b0
264 ; CHECK-LABEL: call_inreg_if:
265 ; HARD: fmovs %f3, %f0
267 ; SOFT: srl %i2, 0, %i0
268 ; SOFT: sllx %i1, 32, %i1
269 ; SOFT: or %i1, %i0, %o0
270 ; CHECK: call inreg_if
271 define void @call_inreg_if(ptr %p, float %f3, i32 %i2) {
272 %x = call i32 @inreg_if(float inreg %f3, i32 inreg %i2)
276 ; The frontend shouldn't do this. Just pass i64 instead.
277 ; CHECK-LABEL: inreg_ii:
278 ; CHECK: srlx %i0, 32, [[R:%[gilo][0-7]]]
279 ; CHECK: sub %i0, [[R]], %i0
280 define i32 @inreg_ii(i32 inreg %a0, ; high bits of %i0
281 i32 inreg %a1) { ; low bits of %i0
282 %rv = sub i32 %a1, %a0
286 ; CHECK-LABEL: call_inreg_ii:
287 ; CHECK: srl %i2, 0, [[R2:%[gilo][0-7]]]
288 ; CHECK: sllx %i1, 32, [[R1:%[gilo][0-7]]]
289 ; CHECK: or [[R1]], [[R2]], %o0
290 ; CHECK: call inreg_ii
291 define void @call_inreg_ii(ptr %p, i32 %i1, i32 %i2) {
292 %x = call i32 @inreg_ii(i32 inreg %i1, i32 inreg %i2)
296 ; This is not a C struct, the i32 member uses 8 bytes, but the float only 4.
297 ; CHECK-LABEL: ret_i32_float_pair:
298 ; CHECK: ld [%i2], %i0
299 ; HARD: ld [%i3], %f2
300 ; SOFT: ld [%i3], %i1
301 define { i32, float } @ret_i32_float_pair(i32 %a0, i32 %a1,
303 %r1 = load i32, ptr %p
304 %rv1 = insertvalue { i32, float } undef, i32 %r1, 0
306 %r2 = load float, ptr %q
307 %rv2 = insertvalue { i32, float } %rv1, float %r2, 1
308 ret { i32, float } %rv2
311 ; CHECK-LABEL: call_ret_i32_float_pair:
312 ; CHECK: call ret_i32_float_pair
313 ; CHECK: st %o0, [%i0]
314 ; HARD: st %f2, [%i1]
315 ; SOFT: st %o1, [%i1]
316 define void @call_ret_i32_float_pair(ptr %i0, ptr %i1) {
317 %rv = call { i32, float } @ret_i32_float_pair(i32 undef, i32 undef,
318 ptr undef, ptr undef)
319 %e0 = extractvalue { i32, float } %rv, 0
320 store i32 %e0, ptr %i0
321 %e1 = extractvalue { i32, float } %rv, 1
322 store float %e1, ptr %i1
326 ; This is a C struct, each member uses 4 bytes.
327 ; CHECK-LABEL: ret_i32_float_packed:
328 ; CHECK: ld [%i2], [[R:%[gilo][0-7]]]
329 ; HARD: ld [%i3], %f1
330 ; SOFT: ld [%i3], %i1
331 ; CHECK: sllx [[R]], 32, %i0
332 define inreg { i32, float } @ret_i32_float_packed(i32 %a0, i32 %a1,
334 %r1 = load i32, ptr %p
335 %rv1 = insertvalue { i32, float } undef, i32 %r1, 0
337 %r2 = load float, ptr %q
338 %rv2 = insertvalue { i32, float } %rv1, float %r2, 1
339 ret { i32, float } %rv2
342 ; CHECK-LABEL: call_ret_i32_float_packed:
343 ; CHECK: call ret_i32_float_packed
344 ; CHECK: srlx %o0, 32, [[R:%[gilo][0-7]]]
345 ; CHECK: st [[R]], [%i0]
346 ; HARD: st %f1, [%i1]
347 ; SOFT: st %o0, [%i1]
348 define void @call_ret_i32_float_packed(ptr %i0, ptr %i1) {
349 %rv = call { i32, float } @ret_i32_float_packed(i32 undef, i32 undef,
350 ptr undef, ptr undef)
351 %e0 = extractvalue { i32, float } %rv, 0
352 store i32 %e0, ptr %i0
353 %e1 = extractvalue { i32, float } %rv, 1
354 store float %e1, ptr %i1
358 ; The C frontend should use i64 to return { i32, i32 } structs, but verify that
359 ; we don't miscompile thi case where both struct elements are placed in %i0.
360 ; CHECK-LABEL: ret_i32_packed:
361 ; CHECK: ld [%i2], [[R1:%[gilo][0-7]]]
362 ; CHECK: ld [%i3], [[R2:%[gilo][0-7]]]
363 ; CHECK: sllx [[R2]], 32, [[R3:%[gilo][0-7]]]
364 ; CHECK: or [[R3]], [[R1]], %i0
365 define inreg { i32, i32 } @ret_i32_packed(i32 %a0, i32 %a1,
367 %r1 = load i32, ptr %p
368 %rv1 = insertvalue { i32, i32 } undef, i32 %r1, 1
370 %r2 = load i32, ptr %q
371 %rv2 = insertvalue { i32, i32 } %rv1, i32 %r2, 0
372 ret { i32, i32 } %rv2
375 ; CHECK-LABEL: call_ret_i32_packed:
376 ; CHECK: call ret_i32_packed
377 ; CHECK: srlx %o0, 32, [[R:%[gilo][0-7]]]
378 ; CHECK: st [[R]], [%i0]
379 ; CHECK: st %o0, [%i1]
380 define void @call_ret_i32_packed(ptr %i0, ptr %i1) {
381 %rv = call { i32, i32 } @ret_i32_packed(i32 undef, i32 undef,
382 ptr undef, ptr undef)
383 %e0 = extractvalue { i32, i32 } %rv, 0
384 store i32 %e0, ptr %i0
385 %e1 = extractvalue { i32, i32 } %rv, 1
386 store i32 %e1, ptr %i1
390 ; The return value must be sign-extended to 64 bits.
391 ; CHECK-LABEL: ret_sext:
392 ; CHECK: sra %i0, 0, %i0
393 define signext i32 @ret_sext(i32 %a0) {
397 ; CHECK-LABEL: ret_zext:
398 ; CHECK: srl %i0, 0, %i0
399 define zeroext i32 @ret_zext(i32 %a0) {
403 ; CHECK-LABEL: ret_nosext:
405 define signext i32 @ret_nosext(i32 signext %a0) {
409 ; CHECK-LABEL: ret_nozext:
411 define signext i32 @ret_nozext(i32 signext %a0) {
415 ; CHECK-LABEL: test_register_directive:
416 ; CHECK: .register %g2, #scratch
417 ; CHECK: .register %g3, #scratch
418 ; CHECK: add %i0, 2, %g2
419 ; CHECK: add %i0, 3, %g3
420 define i32 @test_register_directive(i32 %i0) {
422 %0 = add nsw i32 %i0, 2
423 %1 = add nsw i32 %i0, 3
424 tail call void asm sideeffect "", "r,r,~{l0},~{l1},~{l2},~{l3},~{l4},~{l5},~{l6},~{l7},~{i0},~{i1},~{i2},~{i3},~{i4},~{i5},~{i6},~{i7},~{o0},~{o1},~{o2},~{o3},~{o4},~{o5},~{o6},~{o7},~{g1},~{g4},~{g5},~{g6},~{g7}"(i32 %0, i32 %1)
425 %2 = add nsw i32 %0, %1
429 ; CHECK-LABEL: test_large_stack:
431 ; CHECK: sethi 16, %g1
432 ; CHECK: xor %g1, -176, %g1
433 ; CHECK: save %sp, %g1, %sp
435 ; CHECK: sethi 14, %g1
436 ; CHECK: xor %g1, -1, %g1
437 ; CHECK: add %g1, %fp, %g1
438 ; CHECK: call use_buf
440 define i32 @test_large_stack() {
442 %buffer1 = alloca [16384 x i8], align 8
443 %buffer1.sub = getelementptr inbounds [16384 x i8], ptr %buffer1, i32 0, i32 0
444 %0 = call i32 @use_buf(i32 16384, ptr %buffer1.sub)
448 declare i32 @use_buf(i32, ptr)
450 ; CHECK-LABEL: test_fp128_args:
451 ; HARD-DAG: std %f0, [%fp+{{.+}}]
452 ; HARD-DAG: std %f2, [%fp+{{.+}}]
453 ; HARD-DAG: std %f6, [%fp+{{.+}}]
454 ; HARD-DAG: std %f4, [%fp+{{.+}}]
455 ; HARD: add %fp, [[Offset:[0-9]+]], %o0
457 ; HARD: ldd [%fp+[[Offset]]], %f0
458 ; SOFT-DAG: mov %i0, %o0
459 ; SOFT-DAG: mov %i1, %o1
460 ; SOFT-DAG: mov %i2, %o2
461 ; SOFT-DAG: mov %i3, %o3
462 ; SOFT: call __addtf3
466 define fp128 @test_fp128_args(fp128 %a, fp128 %b) {
468 %0 = fadd fp128 %a, %b
472 declare i64 @receive_fp128(i64 %a, ...)
474 ; CHECK-LABEL: test_fp128_variable_args:
475 ; HARD-DAG: std %f4, [%sp+[[Offset0:[0-9]+]]]
476 ; HARD-DAG: std %f6, [%sp+[[Offset1:[0-9]+]]]
477 ; HARD-DAG: ldx [%sp+[[Offset0]]], %o2
478 ; HARD-DAG: ldx [%sp+[[Offset1]]], %o3
479 ; SOFT-DAG: mov %i0, %o0
480 ; SOFT-DAG: mov %i1, %o1
481 ; SOFT-DAG: mov %i2, %o2
482 ; CHECK: call receive_fp128
483 define i64 @test_fp128_variable_args(i64 %a, fp128 %b) {
485 %0 = call i64 (i64, ...) @receive_fp128(i64 %a, fp128 %b)
489 ; CHECK-LABEL: test_call_libfunc:
490 ; HARD: st %f1, [%fp+[[Offset0:[0-9]+]]]
491 ; HARD: fmovs %f3, %f1
492 ; SOFT: srl %i1, 0, %o0
494 ; HARD: st %f0, [%fp+[[Offset1:[0-9]+]]]
495 ; HARD: ld [%fp+[[Offset0]]], %f1
497 ; SOFT: srl %i0, 0, %o0
499 ; HARD: ld [%fp+[[Offset1]]], %f1
500 ; HARD: fmuls %f1, %f0, %f0
503 ; SOFT: call __mulsf3
504 ; SOFT: sllx %o0, 32, %i0
506 define inreg float @test_call_libfunc(float %arg0, float %arg1) {
508 %0 = tail call inreg float @cosf(float %arg1)
509 %1 = tail call inreg float @sinf(float %arg0)
510 %2 = fmul float %0, %1
514 declare inreg float @cosf(float %arg) readnone nounwind
515 declare inreg float @sinf(float %arg) readnone nounwind