1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 declare void @notdead(i8*)
8 declare i8* @llvm.frameaddress(i32)
9 declare i8* @llvm.returnaddress(i32)
11 define i8* @test_frameaddress_0() nounwind {
12 ; RV32I-LABEL: test_frameaddress_0:
14 ; RV32I-NEXT: addi sp, sp, -16
15 ; RV32I-NEXT: sw ra, 12(sp)
16 ; RV32I-NEXT: sw s0, 8(sp)
17 ; RV32I-NEXT: addi s0, sp, 16
18 ; RV32I-NEXT: mv a0, s0
19 ; RV32I-NEXT: lw s0, 8(sp)
20 ; RV32I-NEXT: lw ra, 12(sp)
21 ; RV32I-NEXT: addi sp, sp, 16
24 ; RV64I-LABEL: test_frameaddress_0:
26 ; RV64I-NEXT: addi sp, sp, -16
27 ; RV64I-NEXT: sd ra, 8(sp)
28 ; RV64I-NEXT: sd s0, 0(sp)
29 ; RV64I-NEXT: addi s0, sp, 16
30 ; RV64I-NEXT: mv a0, s0
31 ; RV64I-NEXT: ld s0, 0(sp)
32 ; RV64I-NEXT: ld ra, 8(sp)
33 ; RV64I-NEXT: addi sp, sp, 16
35 %1 = call i8* @llvm.frameaddress(i32 0)
39 define i8* @test_frameaddress_2() nounwind {
40 ; RV32I-LABEL: test_frameaddress_2:
42 ; RV32I-NEXT: addi sp, sp, -16
43 ; RV32I-NEXT: sw ra, 12(sp)
44 ; RV32I-NEXT: sw s0, 8(sp)
45 ; RV32I-NEXT: addi s0, sp, 16
46 ; RV32I-NEXT: lw a0, -8(s0)
47 ; RV32I-NEXT: lw a0, -8(a0)
48 ; RV32I-NEXT: lw s0, 8(sp)
49 ; RV32I-NEXT: lw ra, 12(sp)
50 ; RV32I-NEXT: addi sp, sp, 16
53 ; RV64I-LABEL: test_frameaddress_2:
55 ; RV64I-NEXT: addi sp, sp, -16
56 ; RV64I-NEXT: sd ra, 8(sp)
57 ; RV64I-NEXT: sd s0, 0(sp)
58 ; RV64I-NEXT: addi s0, sp, 16
59 ; RV64I-NEXT: ld a0, -16(s0)
60 ; RV64I-NEXT: ld a0, -16(a0)
61 ; RV64I-NEXT: ld s0, 0(sp)
62 ; RV64I-NEXT: ld ra, 8(sp)
63 ; RV64I-NEXT: addi sp, sp, 16
65 %1 = call i8* @llvm.frameaddress(i32 2)
69 define i8* @test_frameaddress_3_alloca() nounwind {
70 ; RV32I-LABEL: test_frameaddress_3_alloca:
72 ; RV32I-NEXT: addi sp, sp, -112
73 ; RV32I-NEXT: sw ra, 108(sp)
74 ; RV32I-NEXT: sw s0, 104(sp)
75 ; RV32I-NEXT: addi s0, sp, 112
76 ; RV32I-NEXT: addi a0, s0, -108
77 ; RV32I-NEXT: call notdead
78 ; RV32I-NEXT: lw a0, -8(s0)
79 ; RV32I-NEXT: lw a0, -8(a0)
80 ; RV32I-NEXT: lw a0, -8(a0)
81 ; RV32I-NEXT: lw s0, 104(sp)
82 ; RV32I-NEXT: lw ra, 108(sp)
83 ; RV32I-NEXT: addi sp, sp, 112
86 ; RV64I-LABEL: test_frameaddress_3_alloca:
88 ; RV64I-NEXT: addi sp, sp, -128
89 ; RV64I-NEXT: sd ra, 120(sp)
90 ; RV64I-NEXT: sd s0, 112(sp)
91 ; RV64I-NEXT: addi s0, sp, 128
92 ; RV64I-NEXT: addi a0, s0, -116
93 ; RV64I-NEXT: call notdead
94 ; RV64I-NEXT: ld a0, -16(s0)
95 ; RV64I-NEXT: ld a0, -16(a0)
96 ; RV64I-NEXT: ld a0, -16(a0)
97 ; RV64I-NEXT: ld s0, 112(sp)
98 ; RV64I-NEXT: ld ra, 120(sp)
99 ; RV64I-NEXT: addi sp, sp, 128
101 %1 = alloca [100 x i8]
102 %2 = bitcast [100 x i8]* %1 to i8*
103 call void @notdead(i8* %2)
104 %3 = call i8* @llvm.frameaddress(i32 3)
108 define i8* @test_returnaddress_0() nounwind {
109 ; RV32I-LABEL: test_returnaddress_0:
111 ; RV32I-NEXT: mv a0, ra
114 ; RV64I-LABEL: test_returnaddress_0:
116 ; RV64I-NEXT: mv a0, ra
118 %1 = call i8* @llvm.returnaddress(i32 0)
122 define i8* @test_returnaddress_2() nounwind {
123 ; RV32I-LABEL: test_returnaddress_2:
125 ; RV32I-NEXT: addi sp, sp, -16
126 ; RV32I-NEXT: sw ra, 12(sp)
127 ; RV32I-NEXT: sw s0, 8(sp)
128 ; RV32I-NEXT: addi s0, sp, 16
129 ; RV32I-NEXT: lw a0, -8(s0)
130 ; RV32I-NEXT: lw a0, -8(a0)
131 ; RV32I-NEXT: lw a0, -4(a0)
132 ; RV32I-NEXT: lw s0, 8(sp)
133 ; RV32I-NEXT: lw ra, 12(sp)
134 ; RV32I-NEXT: addi sp, sp, 16
137 ; RV64I-LABEL: test_returnaddress_2:
139 ; RV64I-NEXT: addi sp, sp, -16
140 ; RV64I-NEXT: sd ra, 8(sp)
141 ; RV64I-NEXT: sd s0, 0(sp)
142 ; RV64I-NEXT: addi s0, sp, 16
143 ; RV64I-NEXT: ld a0, -16(s0)
144 ; RV64I-NEXT: ld a0, -16(a0)
145 ; RV64I-NEXT: ld a0, -8(a0)
146 ; RV64I-NEXT: ld s0, 0(sp)
147 ; RV64I-NEXT: ld ra, 8(sp)
148 ; RV64I-NEXT: addi sp, sp, 16
150 %1 = call i8* @llvm.returnaddress(i32 2)