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 i8* %a7) { ; [%fp+BIAS+184]
27 store volatile i8 %a0, i8* %a4
28 store volatile i8 %a1, i8* %a4
29 %p16 = bitcast i8* %a4 to i16*
30 store volatile i16 %a2, i16* %p16
31 %p32 = bitcast i8* %a4 to i32*
32 store volatile i32 %a3, i32* %p32
33 %pp = bitcast i8* %a4 to i8**
34 store volatile i8* %a4, i8** %pp
35 store volatile i32 %a5, i32* %p32
36 store volatile i32 %a6, i32* %p32
37 store volatile i8* %a7, i8** %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, i8* %i1) {
53 call void @intarg(i8 0, i8 1, i16 2, i32 3, i8* undef, i32 5, i32 %i0, i8* %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, double *%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, double* %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 double *%a7, ; [%fp+BIAS+184]
166 i16* %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, double* %a7
171 store i16 %a2, i16* %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, i16* %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(i32* %p, i32 %i1, float %f5) {
225 %x = call i32 @inreg_fi(i32 %i1, float %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(i32* %p, float %f3, float %f5) {
248 %x = call float @inreg_ff(float %f3, float %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(i32* %p, float %f3, i32 %i2) {
272 %x = call i32 @inreg_if(float %f3, i32 %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(i32* %p, i32 %i1, i32 %i2) {
292 %x = call i32 @inreg_ii(i32 %i1, i32 %i2)
296 ; Structs up to 32 bytes in size can be returned in registers.
297 ; CHECK-LABEL: ret_i64_pair:
298 ; CHECK: ldx [%i2], %i0
299 ; CHECK: ldx [%i3], %i1
300 define { i64, i64 } @ret_i64_pair(i32 %a0, i32 %a1, i64* %p, i64* %q) {
301 %r1 = load i64, i64* %p
302 %rv1 = insertvalue { i64, i64 } undef, i64 %r1, 0
304 %r2 = load i64, i64* %q
305 %rv2 = insertvalue { i64, i64 } %rv1, i64 %r2, 1
306 ret { i64, i64 } %rv2
309 ; CHECK-LABEL: call_ret_i64_pair:
310 ; CHECK: call ret_i64_pair
311 ; CHECK: stx %o0, [%i0]
312 ; CHECK: stx %o1, [%i0]
313 define void @call_ret_i64_pair(i64* %i0) {
314 %rv = call { i64, i64 } @ret_i64_pair(i32 undef, i32 undef,
315 i64* undef, i64* undef)
316 %e0 = extractvalue { i64, i64 } %rv, 0
317 store volatile i64 %e0, i64* %i0
318 %e1 = extractvalue { i64, i64 } %rv, 1
319 store i64 %e1, i64* %i0
323 ; This is not a C struct, the i32 member uses 8 bytes, but the float only 4.
324 ; CHECK-LABEL: ret_i32_float_pair:
325 ; CHECK: ld [%i2], %i0
326 ; HARD: ld [%i3], %f2
327 ; SOFT: ld [%i3], %i1
328 define { i32, float } @ret_i32_float_pair(i32 %a0, i32 %a1,
329 i32* %p, float* %q) {
330 %r1 = load i32, i32* %p
331 %rv1 = insertvalue { i32, float } undef, i32 %r1, 0
333 %r2 = load float, float* %q
334 %rv2 = insertvalue { i32, float } %rv1, float %r2, 1
335 ret { i32, float } %rv2
338 ; CHECK-LABEL: call_ret_i32_float_pair:
339 ; CHECK: call ret_i32_float_pair
340 ; CHECK: st %o0, [%i0]
341 ; HARD: st %f2, [%i1]
342 ; SOFT: st %o1, [%i1]
343 define void @call_ret_i32_float_pair(i32* %i0, float* %i1) {
344 %rv = call { i32, float } @ret_i32_float_pair(i32 undef, i32 undef,
345 i32* undef, float* undef)
346 %e0 = extractvalue { i32, float } %rv, 0
347 store i32 %e0, i32* %i0
348 %e1 = extractvalue { i32, float } %rv, 1
349 store float %e1, float* %i1
353 ; This is a C struct, each member uses 4 bytes.
354 ; CHECK-LABEL: ret_i32_float_packed:
355 ; CHECK: ld [%i2], [[R:%[gilo][0-7]]]
356 ; HARD: ld [%i3], %f1
357 ; SOFT: ld [%i3], %i1
358 ; CHECK: sllx [[R]], 32, %i0
359 define inreg { i32, float } @ret_i32_float_packed(i32 %a0, i32 %a1,
360 i32* %p, float* %q) {
361 %r1 = load i32, i32* %p
362 %rv1 = insertvalue { i32, float } undef, i32 %r1, 0
364 %r2 = load float, float* %q
365 %rv2 = insertvalue { i32, float } %rv1, float %r2, 1
366 ret { i32, float } %rv2
369 ; CHECK-LABEL: call_ret_i32_float_packed:
370 ; CHECK: call ret_i32_float_packed
371 ; CHECK: srlx %o0, 32, [[R:%[gilo][0-7]]]
372 ; CHECK: st [[R]], [%i0]
373 ; HARD: st %f1, [%i1]
374 ; SOFT: st %o0, [%i1]
375 define void @call_ret_i32_float_packed(i32* %i0, float* %i1) {
376 %rv = call { i32, float } @ret_i32_float_packed(i32 undef, i32 undef,
377 i32* undef, float* undef)
378 %e0 = extractvalue { i32, float } %rv, 0
379 store i32 %e0, i32* %i0
380 %e1 = extractvalue { i32, float } %rv, 1
381 store float %e1, float* %i1
385 ; The C frontend should use i64 to return { i32, i32 } structs, but verify that
386 ; we don't miscompile thi case where both struct elements are placed in %i0.
387 ; CHECK-LABEL: ret_i32_packed:
388 ; CHECK: ld [%i2], [[R1:%[gilo][0-7]]]
389 ; CHECK: ld [%i3], [[R2:%[gilo][0-7]]]
390 ; CHECK: sllx [[R2]], 32, [[R3:%[gilo][0-7]]]
391 ; CHECK: or [[R3]], [[R1]], %i0
392 define inreg { i32, i32 } @ret_i32_packed(i32 %a0, i32 %a1,
394 %r1 = load i32, i32* %p
395 %rv1 = insertvalue { i32, i32 } undef, i32 %r1, 1
397 %r2 = load i32, i32* %q
398 %rv2 = insertvalue { i32, i32 } %rv1, i32 %r2, 0
399 ret { i32, i32 } %rv2
402 ; CHECK-LABEL: call_ret_i32_packed:
403 ; CHECK: call ret_i32_packed
404 ; CHECK: srlx %o0, 32, [[R:%[gilo][0-7]]]
405 ; CHECK: st [[R]], [%i0]
406 ; CHECK: st %o0, [%i1]
407 define void @call_ret_i32_packed(i32* %i0, i32* %i1) {
408 %rv = call { i32, i32 } @ret_i32_packed(i32 undef, i32 undef,
409 i32* undef, i32* undef)
410 %e0 = extractvalue { i32, i32 } %rv, 0
411 store i32 %e0, i32* %i0
412 %e1 = extractvalue { i32, i32 } %rv, 1
413 store i32 %e1, i32* %i1
417 ; The return value must be sign-extended to 64 bits.
418 ; CHECK-LABEL: ret_sext:
419 ; CHECK: sra %i0, 0, %i0
420 define signext i32 @ret_sext(i32 %a0) {
424 ; CHECK-LABEL: ret_zext:
425 ; CHECK: srl %i0, 0, %i0
426 define zeroext i32 @ret_zext(i32 %a0) {
430 ; CHECK-LABEL: ret_nosext:
432 define signext i32 @ret_nosext(i32 signext %a0) {
436 ; CHECK-LABEL: ret_nozext:
438 define signext i32 @ret_nozext(i32 signext %a0) {
442 ; CHECK-LABEL: test_register_directive:
443 ; CHECK: .register %g2, #scratch
444 ; CHECK: .register %g3, #scratch
445 ; CHECK: add %i0, 2, %g2
446 ; CHECK: add %i0, 3, %g3
447 define i32 @test_register_directive(i32 %i0) {
449 %0 = add nsw i32 %i0, 2
450 %1 = add nsw i32 %i0, 3
451 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)
452 %2 = add nsw i32 %0, %1
456 ; CHECK-LABEL: test_large_stack:
458 ; CHECK: sethi 16, %g1
459 ; CHECK: xor %g1, -176, %g1
460 ; CHECK: save %sp, %g1, %sp
462 ; CHECK: sethi 14, %g1
463 ; CHECK: xor %g1, -1, %g1
464 ; CHECK: add %g1, %fp, %g1
465 ; CHECK: call use_buf
467 define i32 @test_large_stack() {
469 %buffer1 = alloca [16384 x i8], align 8
470 %buffer1.sub = getelementptr inbounds [16384 x i8], [16384 x i8]* %buffer1, i32 0, i32 0
471 %0 = call i32 @use_buf(i32 16384, i8* %buffer1.sub)
475 declare i32 @use_buf(i32, i8*)
477 ; CHECK-LABEL: test_fp128_args:
478 ; HARD-DAG: std %f0, [%fp+{{.+}}]
479 ; HARD-DAG: std %f2, [%fp+{{.+}}]
480 ; HARD-DAG: std %f6, [%fp+{{.+}}]
481 ; HARD-DAG: std %f4, [%fp+{{.+}}]
482 ; HARD: add %fp, [[Offset:[0-9]+]], %o0
484 ; HARD: ldd [%fp+[[Offset]]], %f0
485 ; SOFT-DAG: mov %i0, %o0
486 ; SOFT-DAG: mov %i1, %o1
487 ; SOFT-DAG: mov %i2, %o2
488 ; SOFT-DAG: mov %i3, %o3
489 ; SOFT: call __addtf3
493 define fp128 @test_fp128_args(fp128 %a, fp128 %b) {
495 %0 = fadd fp128 %a, %b
499 declare i64 @receive_fp128(i64 %a, ...)
501 ; CHECK-LABEL: test_fp128_variable_args:
502 ; HARD-DAG: std %f4, [%sp+[[Offset0:[0-9]+]]]
503 ; HARD-DAG: std %f6, [%sp+[[Offset1:[0-9]+]]]
504 ; HARD-DAG: ldx [%sp+[[Offset0]]], %o2
505 ; HARD-DAG: ldx [%sp+[[Offset1]]], %o3
506 ; SOFT-DAG: mov %i0, %o0
507 ; SOFT-DAG: mov %i1, %o1
508 ; SOFT-DAG: mov %i2, %o2
509 ; CHECK: call receive_fp128
510 define i64 @test_fp128_variable_args(i64 %a, fp128 %b) {
512 %0 = call i64 (i64, ...) @receive_fp128(i64 %a, fp128 %b)
516 ; CHECK-LABEL: test_call_libfunc:
517 ; HARD: st %f1, [%fp+[[Offset0:[0-9]+]]]
518 ; HARD: fmovs %f3, %f1
519 ; SOFT: srl %i1, 0, %o0
521 ; HARD: st %f0, [%fp+[[Offset1:[0-9]+]]]
522 ; HARD: ld [%fp+[[Offset0]]], %f1
524 ; SOFT: srl %i0, 0, %o0
526 ; HARD: ld [%fp+[[Offset1]]], %f1
527 ; HARD: fmuls %f1, %f0, %f0
530 ; SOFT: call __mulsf3
531 ; SOFT: sllx %o0, 32, %i0
533 define inreg float @test_call_libfunc(float %arg0, float %arg1) {
535 %0 = tail call inreg float @cosf(float %arg1)
536 %1 = tail call inreg float @sinf(float %arg0)
537 %2 = fmul float %0, %1
541 declare inreg float @cosf(float %arg) readnone nounwind
542 declare inreg float @sinf(float %arg) readnone nounwind