xref: /aosp_15_r20/external/llvm/test/CodeGen/SPARC/spill.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=sparc  < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker;; Ensure that spills and reloads work for various types on
4*9880d681SAndroid Build Coastguard Worker;; sparcv8.
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Worker;; For i32/i64 tests, use an asm statement which clobbers most
7*9880d681SAndroid Build Coastguard Worker;; registers to ensure the spill will happen.
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_i32_spill:
10*9880d681SAndroid Build Coastguard Worker; CHECK:       and %i0, %i1, %o0
11*9880d681SAndroid Build Coastguard Worker; CHECK:       st %o0, [%fp+{{.+}}]
12*9880d681SAndroid Build Coastguard Worker; CHECK:       add %o0, %o0, %g0
13*9880d681SAndroid Build Coastguard Worker; CHECK:       ld [%fp+{{.+}}, %i0
14*9880d681SAndroid Build Coastguard Workerdefine i32 @test_i32_spill(i32 %a, i32 %b) {
15*9880d681SAndroid Build Coastguard Workerentry:
16*9880d681SAndroid Build Coastguard Worker  %r0 = and i32 %a, %b
17*9880d681SAndroid Build Coastguard Worker  ; The clobber list has all registers except g0/o0. (Only o0 is usable.)
18*9880d681SAndroid Build Coastguard Worker  %0 = call i32 asm sideeffect "add $0,$1,%g0", "=r,0,~{i0},~{i1},~{i2},~{i3},~{i4},~{i5},~{i6},~{i7},~{g1},~{g2},~{g3},~{g4},~{g5},~{g6},~{g7},~{l0},~{l1},~{l2},~{l3},~{l4},~{l5},~{l6},~{l7},~{o1},~{o2},~{o3},~{o4},~{o5},~{o6},~{o7}"(i32 %r0)
19*9880d681SAndroid Build Coastguard Worker  ret i32 %r0
20*9880d681SAndroid Build Coastguard Worker}
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_i64_spill:
23*9880d681SAndroid Build Coastguard Worker; CHECK:       and %i0, %i2, %o0
24*9880d681SAndroid Build Coastguard Worker; CHECK:       and %i1, %i3, %o1
25*9880d681SAndroid Build Coastguard Worker; CHECK:       std %o0, [%fp+{{.+}}]
26*9880d681SAndroid Build Coastguard Worker; CHECK:       add %o0, %o0, %g0
27*9880d681SAndroid Build Coastguard Worker; CHECK:       ldd [%fp+{{.+}}, %i0
28*9880d681SAndroid Build Coastguard Workerdefine i64 @test_i64_spill(i64 %a, i64 %b) {
29*9880d681SAndroid Build Coastguard Workerentry:
30*9880d681SAndroid Build Coastguard Worker  %r0 = and i64 %a, %b
31*9880d681SAndroid Build Coastguard Worker  ; The clobber list has all registers except g0,g1,o0,o1. (Only o0/o1 are a usable pair)
32*9880d681SAndroid Build Coastguard Worker  ; So, o0/o1 must be used.
33*9880d681SAndroid Build Coastguard Worker  %0 = call i64 asm sideeffect "add $0,$1,%g0", "=r,0,~{i0},~{i1},~{i2},~{i3},~{i4},~{i5},~{i6},~{i7},~{g2},~{g3},~{g4},~{g5},~{g6},~{g7},~{l0},~{l1},~{l2},~{l3},~{l4},~{l5},~{l6},~{l7},~{o2},~{o3},~{o4},~{o5},~{o7}"(i64 %r0)
34*9880d681SAndroid Build Coastguard Worker  ret i64 %r0
35*9880d681SAndroid Build Coastguard Worker}
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker;; For float/double tests, a call is a suitable clobber as *all* FPU
38*9880d681SAndroid Build Coastguard Worker;; registers are caller-save on sparcv8.
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_float_spill:
41*9880d681SAndroid Build Coastguard Worker; CHECK:       fadds %f1, %f0, [[R:%[f][0-31]]]
42*9880d681SAndroid Build Coastguard Worker; CHECK:       st [[R]], [%fp+{{.+}}]
43*9880d681SAndroid Build Coastguard Worker; CHECK:       call
44*9880d681SAndroid Build Coastguard Worker; CHECK:       ld [%fp+{{.+}}, %f0
45*9880d681SAndroid Build Coastguard Workerdeclare float @foo_float(float)
46*9880d681SAndroid Build Coastguard Workerdefine float @test_float_spill(float %a, float %b) {
47*9880d681SAndroid Build Coastguard Workerentry:
48*9880d681SAndroid Build Coastguard Worker  %r0 = fadd float %a, %b
49*9880d681SAndroid Build Coastguard Worker  %0 = call float @foo_float(float %r0)
50*9880d681SAndroid Build Coastguard Worker  ret float %r0
51*9880d681SAndroid Build Coastguard Worker}
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_double_spill:
54*9880d681SAndroid Build Coastguard Worker; CHECK:       faddd %f2, %f0, [[R:%[f][0-31]]]
55*9880d681SAndroid Build Coastguard Worker; CHECK:       std [[R]], [%fp+{{.+}}]
56*9880d681SAndroid Build Coastguard Worker; CHECK:       call
57*9880d681SAndroid Build Coastguard Worker; CHECK:       ldd [%fp+{{.+}}, %f0
58*9880d681SAndroid Build Coastguard Workerdeclare double @foo_double(double)
59*9880d681SAndroid Build Coastguard Workerdefine double @test_double_spill(double %a, double %b) {
60*9880d681SAndroid Build Coastguard Workerentry:
61*9880d681SAndroid Build Coastguard Worker  %r0 = fadd double %a, %b
62*9880d681SAndroid Build Coastguard Worker  %0 = call double @foo_double(double %r0)
63*9880d681SAndroid Build Coastguard Worker  ret double %r0
64*9880d681SAndroid Build Coastguard Worker}
65