1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 < %s \
3 ; RUN: | FileCheck -check-prefix=RV32 %s
4 ; RUN: llc -mtriple=riscv64 < %s \
5 ; RUN: | FileCheck -check-prefix=RV64 %s
6 ; RUN: llc -mtriple=riscv32 -frame-pointer=all -verify-machineinstrs < %s \
7 ; RUN: | FileCheck -check-prefix=RV32-WITHFP %s
8 ; RUN: llc -mtriple=riscv64 -frame-pointer=all -verify-machineinstrs < %s \
9 ; RUN: | FileCheck -check-prefix=RV64-WITHFP %s
11 define void @trivial() {
12 ; RV32-LABEL: trivial:
16 ; RV64-LABEL: trivial:
20 ; RV32-WITHFP-LABEL: trivial:
21 ; RV32-WITHFP: # %bb.0:
22 ; RV32-WITHFP-NEXT: addi sp, sp, -16
23 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
24 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
25 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
26 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
27 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
28 ; RV32-WITHFP-NEXT: addi s0, sp, 16
29 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
30 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
31 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
32 ; RV32-WITHFP-NEXT: addi sp, sp, 16
33 ; RV32-WITHFP-NEXT: ret
35 ; RV64-WITHFP-LABEL: trivial:
36 ; RV64-WITHFP: # %bb.0:
37 ; RV64-WITHFP-NEXT: addi sp, sp, -16
38 ; RV64-WITHFP-NEXT: .cfi_def_cfa_offset 16
39 ; RV64-WITHFP-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
40 ; RV64-WITHFP-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
41 ; RV64-WITHFP-NEXT: .cfi_offset ra, -8
42 ; RV64-WITHFP-NEXT: .cfi_offset s0, -16
43 ; RV64-WITHFP-NEXT: addi s0, sp, 16
44 ; RV64-WITHFP-NEXT: .cfi_def_cfa s0, 0
45 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
46 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
47 ; RV64-WITHFP-NEXT: addi sp, sp, 16
48 ; RV64-WITHFP-NEXT: ret
52 define void @stack_alloc(i32 signext %size) {
53 ; RV32-LABEL: stack_alloc:
54 ; RV32: # %bb.0: # %entry
55 ; RV32-NEXT: addi sp, sp, -16
56 ; RV32-NEXT: .cfi_def_cfa_offset 16
57 ; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
58 ; RV32-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
59 ; RV32-NEXT: .cfi_offset ra, -4
60 ; RV32-NEXT: .cfi_offset s0, -8
61 ; RV32-NEXT: addi s0, sp, 16
62 ; RV32-NEXT: .cfi_def_cfa s0, 0
63 ; RV32-NEXT: addi a0, a0, 15
64 ; RV32-NEXT: andi a0, a0, -16
65 ; RV32-NEXT: sub a0, sp, a0
66 ; RV32-NEXT: mv sp, a0
67 ; RV32-NEXT: call callee_with_args
68 ; RV32-NEXT: addi sp, s0, -16
69 ; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
70 ; RV32-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
71 ; RV32-NEXT: addi sp, sp, 16
74 ; RV64-LABEL: stack_alloc:
75 ; RV64: # %bb.0: # %entry
76 ; RV64-NEXT: addi sp, sp, -16
77 ; RV64-NEXT: .cfi_def_cfa_offset 16
78 ; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
79 ; RV64-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
80 ; RV64-NEXT: .cfi_offset ra, -8
81 ; RV64-NEXT: .cfi_offset s0, -16
82 ; RV64-NEXT: addi s0, sp, 16
83 ; RV64-NEXT: .cfi_def_cfa s0, 0
84 ; RV64-NEXT: slli a0, a0, 32
85 ; RV64-NEXT: srli a0, a0, 32
86 ; RV64-NEXT: addi a0, a0, 15
87 ; RV64-NEXT: andi a0, a0, -16
88 ; RV64-NEXT: sub a0, sp, a0
89 ; RV64-NEXT: mv sp, a0
90 ; RV64-NEXT: call callee_with_args
91 ; RV64-NEXT: addi sp, s0, -16
92 ; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
93 ; RV64-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
94 ; RV64-NEXT: addi sp, sp, 16
97 ; RV32-WITHFP-LABEL: stack_alloc:
98 ; RV32-WITHFP: # %bb.0: # %entry
99 ; RV32-WITHFP-NEXT: addi sp, sp, -16
100 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
101 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
102 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
103 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
104 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
105 ; RV32-WITHFP-NEXT: addi s0, sp, 16
106 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
107 ; RV32-WITHFP-NEXT: addi a0, a0, 15
108 ; RV32-WITHFP-NEXT: andi a0, a0, -16
109 ; RV32-WITHFP-NEXT: sub a0, sp, a0
110 ; RV32-WITHFP-NEXT: mv sp, a0
111 ; RV32-WITHFP-NEXT: call callee_with_args
112 ; RV32-WITHFP-NEXT: addi sp, s0, -16
113 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
114 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
115 ; RV32-WITHFP-NEXT: addi sp, sp, 16
116 ; RV32-WITHFP-NEXT: ret
118 ; RV64-WITHFP-LABEL: stack_alloc:
119 ; RV64-WITHFP: # %bb.0: # %entry
120 ; RV64-WITHFP-NEXT: addi sp, sp, -16
121 ; RV64-WITHFP-NEXT: .cfi_def_cfa_offset 16
122 ; RV64-WITHFP-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
123 ; RV64-WITHFP-NEXT: sd s0, 0(sp) # 8-byte Folded Spill
124 ; RV64-WITHFP-NEXT: .cfi_offset ra, -8
125 ; RV64-WITHFP-NEXT: .cfi_offset s0, -16
126 ; RV64-WITHFP-NEXT: addi s0, sp, 16
127 ; RV64-WITHFP-NEXT: .cfi_def_cfa s0, 0
128 ; RV64-WITHFP-NEXT: slli a0, a0, 32
129 ; RV64-WITHFP-NEXT: srli a0, a0, 32
130 ; RV64-WITHFP-NEXT: addi a0, a0, 15
131 ; RV64-WITHFP-NEXT: andi a0, a0, -16
132 ; RV64-WITHFP-NEXT: sub a0, sp, a0
133 ; RV64-WITHFP-NEXT: mv sp, a0
134 ; RV64-WITHFP-NEXT: call callee_with_args
135 ; RV64-WITHFP-NEXT: addi sp, s0, -16
136 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
137 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
138 ; RV64-WITHFP-NEXT: addi sp, sp, 16
139 ; RV64-WITHFP-NEXT: ret
141 %0 = alloca i8, i32 %size, align 16
142 call void @callee_with_args(ptr nonnull %0)
146 define void @branch_and_tail_call(i1 %a) {
147 ; RV32-LABEL: branch_and_tail_call:
149 ; RV32-NEXT: andi a0, a0, 1
150 ; RV32-NEXT: beqz a0, .LBB2_2
151 ; RV32-NEXT: # %bb.1: # %blue_pill
152 ; RV32-NEXT: tail callee1
153 ; RV32-NEXT: .LBB2_2: # %red_pill
154 ; RV32-NEXT: addi sp, sp, -16
155 ; RV32-NEXT: .cfi_def_cfa_offset 16
156 ; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
157 ; RV32-NEXT: .cfi_offset ra, -4
158 ; RV32-NEXT: call callee2
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: andi a0, a0, 1
166 ; RV64-NEXT: beqz a0, .LBB2_2
167 ; RV64-NEXT: # %bb.1: # %blue_pill
168 ; RV64-NEXT: tail callee1
169 ; RV64-NEXT: .LBB2_2: # %red_pill
170 ; RV64-NEXT: addi sp, sp, -16
171 ; RV64-NEXT: .cfi_def_cfa_offset 16
172 ; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
173 ; RV64-NEXT: .cfi_offset ra, -8
174 ; RV64-NEXT: call callee2
175 ; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
176 ; RV64-NEXT: addi sp, sp, 16
179 ; RV32-WITHFP-LABEL: branch_and_tail_call:
180 ; RV32-WITHFP: # %bb.0:
181 ; RV32-WITHFP-NEXT: andi a0, a0, 1
182 ; RV32-WITHFP-NEXT: beqz a0, .LBB2_2
183 ; RV32-WITHFP-NEXT: # %bb.1: # %blue_pill
184 ; RV32-WITHFP-NEXT: tail callee1
185 ; RV32-WITHFP-NEXT: .LBB2_2: # %red_pill
186 ; RV32-WITHFP-NEXT: addi sp, sp, -16
187 ; RV32-WITHFP-NEXT: .cfi_def_cfa_offset 16
188 ; RV32-WITHFP-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
189 ; RV32-WITHFP-NEXT: sw s0, 8(sp) # 4-byte Folded Spill
190 ; RV32-WITHFP-NEXT: .cfi_offset ra, -4
191 ; RV32-WITHFP-NEXT: .cfi_offset s0, -8
192 ; RV32-WITHFP-NEXT: addi s0, sp, 16
193 ; RV32-WITHFP-NEXT: .cfi_def_cfa s0, 0
194 ; RV32-WITHFP-NEXT: call callee2
195 ; RV32-WITHFP-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
196 ; RV32-WITHFP-NEXT: lw s0, 8(sp) # 4-byte Folded Reload
197 ; RV32-WITHFP-NEXT: addi sp, sp, 16
198 ; RV32-WITHFP-NEXT: ret
200 ; RV64-WITHFP-LABEL: branch_and_tail_call:
201 ; RV64-WITHFP: # %bb.0:
202 ; RV64-WITHFP-NEXT: andi a0, a0, 1
203 ; RV64-WITHFP-NEXT: beqz a0, .LBB2_2
204 ; RV64-WITHFP-NEXT: # %bb.1: # %blue_pill
205 ; RV64-WITHFP-NEXT: tail callee1
206 ; RV64-WITHFP-NEXT: .LBB2_2: # %red_pill
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: call callee2
216 ; RV64-WITHFP-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
217 ; RV64-WITHFP-NEXT: ld s0, 0(sp) # 8-byte Folded Reload
218 ; RV64-WITHFP-NEXT: addi sp, sp, 16
219 ; RV64-WITHFP-NEXT: ret
220 br i1 %a, label %blue_pill, label %red_pill
222 tail call void @callee1()
229 declare void @callee1()
230 declare void @callee2()
231 declare void @callee_with_args(ptr)