1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 < %s | FileCheck -check-prefix=RV32 %s
3 ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=RV64 %s
4 ; RUN: llc -mtriple=riscv32 -frame-pointer=all -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV32-WITHFP %s
6 ; RUN: llc -mtriple=riscv64 -frame-pointer=all -verify-machineinstrs < %s \
7 ; RUN: | FileCheck -check-prefix=RV64-WITHFP %s
9 define void @trivial() {
10 ; RV32-LABEL: trivial:
14 ; RV64-LABEL: trivial:
18 ; RV32-WITHFP-LABEL: trivial:
19 ; RV32-WITHFP: # %bb.0:
20 ; RV32-WITHFP-NEXT: addi sp, sp, -16
21 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
22 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
23 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
24 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
25 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
26 ; RV32-WITHFP-NEXT: addi s0, sp, 16
27 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
28 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
29 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
30 ; RV32-WITHFP-NEXT: addi sp, sp, 16
31 ; RV32-WITHFP-NEXT: ret
33 ; RV64-WITHFP-LABEL: trivial:
34 ; RV64-WITHFP: # %bb.0:
35 ; RV64-WITHFP-NEXT: addi sp, sp, -16
36 ; RV64-WITHFP-NEXT: .cfi_def_cfa_offset 16
37 ; RV64-WITHFP-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
38 ; RV64-WITHFP-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
39 ; RV64-WITHFP-NEXT: .cfi_offset ra, -8
40 ; RV64-WITHFP-NEXT: .cfi_offset s0, -16
41 ; RV64-WITHFP-NEXT: addi s0, sp, 16
42 ; RV64-WITHFP-NEXT: .cfi_def_cfa s0, 0
43 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
44 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
45 ; RV64-WITHFP-NEXT: addi sp, sp, 16
46 ; RV64-WITHFP-NEXT: ret
50 define void @stack_alloc(i32 signext %size) {
51 ; RV32-LABEL: stack_alloc:
52 ; RV32: # %bb.0: # %entry
53 ; RV32-NEXT: addi sp, sp, -16
54 ; RV32-NEXT: .cfi_def_cfa_offset 16
55 ; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
56 ; RV32-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
57 ; RV32-NEXT: .cfi_offset ra, -4
58 ; RV32-NEXT: .cfi_offset s0, -8
59 ; RV32-NEXT: addi s0, sp, 16
60 ; RV32-NEXT: .cfi_def_cfa s0, 0
61 ; RV32-NEXT: addi a0, a0, 15
62 ; RV32-NEXT: andi a0, a0, -16
63 ; RV32-NEXT: sub a0, sp, a0
64 ; RV32-NEXT: mv sp, a0
65 ; RV32-NEXT: call callee_with_args@plt
66 ; RV32-NEXT: addi sp, s0, -16
67 ; RV32-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
68 ; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
69 ; RV32-NEXT: addi sp, sp, 16
72 ; RV64-LABEL: stack_alloc:
73 ; RV64: # %bb.0: # %entry
74 ; RV64-NEXT: addi sp, sp, -16
75 ; RV64-NEXT: .cfi_def_cfa_offset 16
76 ; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
77 ; RV64-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
78 ; RV64-NEXT: .cfi_offset ra, -8
79 ; RV64-NEXT: .cfi_offset s0, -16
80 ; RV64-NEXT: addi s0, sp, 16
81 ; RV64-NEXT: .cfi_def_cfa s0, 0
82 ; RV64-NEXT: slli a0, a0, 32
83 ; RV64-NEXT: srli a0, a0, 32
84 ; RV64-NEXT: addi a0, a0, 15
85 ; RV64-NEXT: andi a0, a0, -16
86 ; RV64-NEXT: sub a0, sp, a0
87 ; RV64-NEXT: mv sp, a0
88 ; RV64-NEXT: call callee_with_args@plt
89 ; RV64-NEXT: addi sp, s0, -16
90 ; RV64-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
91 ; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
92 ; RV64-NEXT: addi sp, sp, 16
95 ; RV32-WITHFP-LABEL: stack_alloc:
96 ; RV32-WITHFP: # %bb.0: # %entry
97 ; RV32-WITHFP-NEXT: addi sp, sp, -16
98 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
99 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
100 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
101 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
102 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
103 ; RV32-WITHFP-NEXT: addi s0, sp, 16
104 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
105 ; RV32-WITHFP-NEXT: addi a0, a0, 15
106 ; RV32-WITHFP-NEXT: andi a0, a0, -16
107 ; RV32-WITHFP-NEXT: sub a0, sp, a0
108 ; RV32-WITHFP-NEXT: mv sp, a0
109 ; RV32-WITHFP-NEXT: call callee_with_args@plt
110 ; RV32-WITHFP-NEXT: addi sp, s0, -16
111 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
112 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
113 ; RV32-WITHFP-NEXT: addi sp, sp, 16
114 ; RV32-WITHFP-NEXT: ret
116 ; RV64-WITHFP-LABEL: stack_alloc:
117 ; RV64-WITHFP: # %bb.0: # %entry
118 ; RV64-WITHFP-NEXT: addi sp, sp, -16
119 ; RV64-WITHFP-NEXT: .cfi_def_cfa_offset 16
120 ; RV64-WITHFP-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
121 ; RV64-WITHFP-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
122 ; RV64-WITHFP-NEXT: .cfi_offset ra, -8
123 ; RV64-WITHFP-NEXT: .cfi_offset s0, -16
124 ; RV64-WITHFP-NEXT: addi s0, sp, 16
125 ; RV64-WITHFP-NEXT: .cfi_def_cfa s0, 0
126 ; RV64-WITHFP-NEXT: slli a0, a0, 32
127 ; RV64-WITHFP-NEXT: srli a0, a0, 32
128 ; RV64-WITHFP-NEXT: addi a0, a0, 15
129 ; RV64-WITHFP-NEXT: andi a0, a0, -16
130 ; RV64-WITHFP-NEXT: sub a0, sp, a0
131 ; RV64-WITHFP-NEXT: mv sp, a0
132 ; RV64-WITHFP-NEXT: call callee_with_args@plt
133 ; RV64-WITHFP-NEXT: addi sp, s0, -16
134 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
135 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
136 ; RV64-WITHFP-NEXT: addi sp, sp, 16
137 ; RV64-WITHFP-NEXT: ret
139 %0 = alloca i8, i32 %size, align 16
140 call void @callee_with_args(i8* nonnull %0)
144 define void @branch_and_tail_call(i1 %a) {
145 ; RV32-LABEL: branch_and_tail_call:
147 ; RV32-NEXT: addi sp, sp, -16
148 ; RV32-NEXT: .cfi_def_cfa_offset 16
149 ; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
150 ; RV32-NEXT: .cfi_offset ra, -4
151 ; RV32-NEXT: andi a0, a0, 1
152 ; RV32-NEXT: beqz a0, .LBB2_2
153 ; RV32-NEXT: # %bb.1: # %blue_pill
154 ; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
155 ; RV32-NEXT: addi sp, sp, 16
156 ; RV32-NEXT: tail callee1@plt
157 ; RV32-NEXT: .LBB2_2: # %red_pill
158 ; RV32-NEXT: call callee2@plt
159 ; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
160 ; RV32-NEXT: addi sp, sp, 16
163 ; RV64-LABEL: branch_and_tail_call:
165 ; RV64-NEXT: addi sp, sp, -16
166 ; RV64-NEXT: .cfi_def_cfa_offset 16
167 ; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
168 ; RV64-NEXT: .cfi_offset ra, -8
169 ; RV64-NEXT: andi a0, a0, 1
170 ; RV64-NEXT: beqz a0, .LBB2_2
171 ; RV64-NEXT: # %bb.1: # %blue_pill
172 ; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
173 ; RV64-NEXT: addi sp, sp, 16
174 ; RV64-NEXT: tail callee1@plt
175 ; RV64-NEXT: .LBB2_2: # %red_pill
176 ; RV64-NEXT: call callee2@plt
177 ; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
178 ; RV64-NEXT: addi sp, sp, 16
181 ; RV32-WITHFP-LABEL: branch_and_tail_call:
182 ; RV32-WITHFP: # %bb.0:
183 ; RV32-WITHFP-NEXT: addi sp, sp, -16
184 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
185 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
186 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
187 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
188 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
189 ; RV32-WITHFP-NEXT: addi s0, sp, 16
190 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
191 ; RV32-WITHFP-NEXT: andi a0, a0, 1
192 ; RV32-WITHFP-NEXT: beqz a0, .LBB2_2
193 ; RV32-WITHFP-NEXT: # %bb.1: # %blue_pill
194 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
195 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
196 ; RV32-WITHFP-NEXT: addi sp, sp, 16
197 ; RV32-WITHFP-NEXT: tail callee1@plt
198 ; RV32-WITHFP-NEXT: .LBB2_2: # %red_pill
199 ; RV32-WITHFP-NEXT: call callee2@plt
200 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
201 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
202 ; RV32-WITHFP-NEXT: addi sp, sp, 16
203 ; RV32-WITHFP-NEXT: ret
205 ; RV64-WITHFP-LABEL: branch_and_tail_call:
206 ; RV64-WITHFP: # %bb.0:
207 ; RV64-WITHFP-NEXT: addi sp, sp, -16
208 ; RV64-WITHFP-NEXT: .cfi_def_cfa_offset 16
209 ; RV64-WITHFP-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
210 ; RV64-WITHFP-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
211 ; RV64-WITHFP-NEXT: .cfi_offset ra, -8
212 ; RV64-WITHFP-NEXT: .cfi_offset s0, -16
213 ; RV64-WITHFP-NEXT: addi s0, sp, 16
214 ; RV64-WITHFP-NEXT: .cfi_def_cfa s0, 0
215 ; RV64-WITHFP-NEXT: andi a0, a0, 1
216 ; RV64-WITHFP-NEXT: beqz a0, .LBB2_2
217 ; RV64-WITHFP-NEXT: # %bb.1: # %blue_pill
218 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
219 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
220 ; RV64-WITHFP-NEXT: addi sp, sp, 16
221 ; RV64-WITHFP-NEXT: tail callee1@plt
222 ; RV64-WITHFP-NEXT: .LBB2_2: # %red_pill
223 ; RV64-WITHFP-NEXT: call callee2@plt
224 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
225 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
226 ; RV64-WITHFP-NEXT: addi sp, sp, 16
227 ; RV64-WITHFP-NEXT: ret
228 br i1 %a, label %blue_pill, label %red_pill
230 tail call void @callee1()
237 declare void @callee1()
238 declare void @callee2()
239 declare void @callee_with_args(i8*)