1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
5 ; Check indexed and unindexed, sext, zext and anyext loads
7 define dso_local i32 @lb(i8 *%a) nounwind {
10 ; RV32I-NEXT: lb a1, 1(a0)
11 ; RV32I-NEXT: lb a0, 0(a0)
12 ; RV32I-NEXT: mv a0, a1
14 %1 = getelementptr i8, i8* %a, i32 1
16 %3 = sext i8 %2 to i32
17 ; the unused load will produce an anyext for selection
18 %4 = load volatile i8, i8* %a
22 define dso_local i32 @lh(i16 *%a) nounwind {
25 ; RV32I-NEXT: lh a1, 4(a0)
26 ; RV32I-NEXT: lh a0, 0(a0)
27 ; RV32I-NEXT: mv a0, a1
29 %1 = getelementptr i16, i16* %a, i32 2
30 %2 = load i16, i16* %1
31 %3 = sext i16 %2 to i32
32 ; the unused load will produce an anyext for selection
33 %4 = load volatile i16, i16* %a
37 define dso_local i32 @lw(i32 *%a) nounwind {
40 ; RV32I-NEXT: lw a1, 12(a0)
41 ; RV32I-NEXT: lw a0, 0(a0)
42 ; RV32I-NEXT: mv a0, a1
44 %1 = getelementptr i32, i32* %a, i32 3
45 %2 = load i32, i32* %1
46 %3 = load volatile i32, i32* %a
50 define dso_local i32 @lbu(i8 *%a) nounwind {
53 ; RV32I-NEXT: lbu a1, 4(a0)
54 ; RV32I-NEXT: lbu a0, 0(a0)
55 ; RV32I-NEXT: add a0, a1, a0
57 %1 = getelementptr i8, i8* %a, i32 4
59 %3 = zext i8 %2 to i32
60 %4 = load volatile i8, i8* %a
61 %5 = zext i8 %4 to i32
66 define dso_local i32 @lhu(i16 *%a) nounwind {
69 ; RV32I-NEXT: lhu a1, 10(a0)
70 ; RV32I-NEXT: lhu a0, 0(a0)
71 ; RV32I-NEXT: add a0, a1, a0
73 %1 = getelementptr i16, i16* %a, i32 5
74 %2 = load i16, i16* %1
75 %3 = zext i16 %2 to i32
76 %4 = load volatile i16, i16* %a
77 %5 = zext i16 %4 to i32
82 ; Check indexed and unindexed stores
84 define dso_local void @sb(i8 *%a, i8 %b) nounwind {
87 ; RV32I-NEXT: sb a1, 0(a0)
88 ; RV32I-NEXT: sb a1, 6(a0)
91 %1 = getelementptr i8, i8* %a, i32 6
96 define dso_local void @sh(i16 *%a, i16 %b) nounwind {
99 ; RV32I-NEXT: sh a1, 0(a0)
100 ; RV32I-NEXT: sh a1, 14(a0)
102 store i16 %b, i16* %a
103 %1 = getelementptr i16, i16* %a, i32 7
104 store i16 %b, i16* %1
108 define dso_local void @sw(i32 *%a, i32 %b) nounwind {
111 ; RV32I-NEXT: sw a1, 0(a0)
112 ; RV32I-NEXT: sw a1, 32(a0)
114 store i32 %b, i32* %a
115 %1 = getelementptr i32, i32* %a, i32 8
116 store i32 %b, i32* %1
120 ; Check load and store to an i1 location
121 define dso_local i32 @load_sext_zext_anyext_i1(i1 *%a) nounwind {
122 ; RV32I-LABEL: load_sext_zext_anyext_i1:
124 ; RV32I-NEXT: lbu a1, 1(a0)
125 ; RV32I-NEXT: lbu a2, 2(a0)
126 ; RV32I-NEXT: lb a0, 0(a0)
127 ; RV32I-NEXT: sub a0, a2, a1
130 %1 = getelementptr i1, i1* %a, i32 1
132 %3 = sext i1 %2 to i32
134 %4 = getelementptr i1, i1* %a, i32 2
136 %6 = zext i1 %5 to i32
138 ; extload i1 (anyext). Produced as the load is unused.
139 %8 = load volatile i1, i1* %a
143 define dso_local i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind {
144 ; RV32I-LABEL: load_sext_zext_anyext_i1_i16:
146 ; RV32I-NEXT: lbu a1, 1(a0)
147 ; RV32I-NEXT: lbu a2, 2(a0)
148 ; RV32I-NEXT: lb a0, 0(a0)
149 ; RV32I-NEXT: sub a0, a2, a1
152 %1 = getelementptr i1, i1* %a, i32 1
154 %3 = sext i1 %2 to i16
156 %4 = getelementptr i1, i1* %a, i32 2
158 %6 = zext i1 %5 to i16
160 ; extload i1 (anyext). Produced as the load is unused.
161 %8 = load volatile i1, i1* %a
165 ; Check load and store to a global
166 @G = dso_local global i32 0
168 define dso_local i32 @lw_sw_global(i32 %a) nounwind {
169 ; RV32I-LABEL: lw_sw_global:
171 ; RV32I-NEXT: lui a2, %hi(G)
172 ; RV32I-NEXT: lw a1, %lo(G)(a2)
173 ; RV32I-NEXT: addi a3, a2, %lo(G)
174 ; RV32I-NEXT: sw a0, %lo(G)(a2)
175 ; RV32I-NEXT: lw a2, 36(a3)
176 ; RV32I-NEXT: sw a0, 36(a3)
177 ; RV32I-NEXT: mv a0, a1
179 %1 = load volatile i32, i32* @G
180 store i32 %a, i32* @G
181 %2 = getelementptr i32, i32* @G, i32 9
182 %3 = load volatile i32, i32* %2
183 store i32 %a, i32* %2
187 ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1
188 define dso_local i32 @lw_sw_constant(i32 %a) nounwind {
189 ; RV32I-LABEL: lw_sw_constant:
191 ; RV32I-NEXT: lui a2, 912092
192 ; RV32I-NEXT: lw a1, -273(a2)
193 ; RV32I-NEXT: sw a0, -273(a2)
194 ; RV32I-NEXT: mv a0, a1
196 %1 = inttoptr i32 3735928559 to i32*
197 %2 = load volatile i32, i32* %1
198 store i32 %a, i32* %1
202 define i32 @lw_near_local(i32* %a) {
203 ; RV32I-LABEL: lw_near_local:
205 ; RV32I-NEXT: addi a0, a0, 2047
206 ; RV32I-NEXT: lw a0, 5(a0)
208 %1 = getelementptr inbounds i32, i32* %a, i64 513
209 %2 = load volatile i32, i32* %1
213 define void @st_near_local(i32* %a, i32 %b) {
214 ; RV32I-LABEL: st_near_local:
216 ; RV32I-NEXT: addi a0, a0, 2047
217 ; RV32I-NEXT: sw a1, 5(a0)
219 %1 = getelementptr inbounds i32, i32* %a, i64 513
220 store i32 %b, i32* %1
224 define i32 @lw_sw_near_local(i32* %a, i32 %b) {
225 ; RV32I-LABEL: lw_sw_near_local:
227 ; RV32I-NEXT: addi a2, a0, 2047
228 ; RV32I-NEXT: lw a0, 5(a2)
229 ; RV32I-NEXT: sw a1, 5(a2)
231 %1 = getelementptr inbounds i32, i32* %a, i64 513
232 %2 = load volatile i32, i32* %1
233 store i32 %b, i32* %1
237 define i32 @lw_far_local(i32* %a) {
238 ; RV32I-LABEL: lw_far_local:
240 ; RV32I-NEXT: lui a1, 4
241 ; RV32I-NEXT: add a0, a0, a1
242 ; RV32I-NEXT: lw a0, -4(a0)
244 %1 = getelementptr inbounds i32, i32* %a, i64 4095
245 %2 = load volatile i32, i32* %1
249 define void @st_far_local(i32* %a, i32 %b) {
250 ; RV32I-LABEL: st_far_local:
252 ; RV32I-NEXT: lui a2, 4
253 ; RV32I-NEXT: add a0, a0, a2
254 ; RV32I-NEXT: sw a1, -4(a0)
256 %1 = getelementptr inbounds i32, i32* %a, i64 4095
257 store i32 %b, i32* %1
261 define i32 @lw_sw_far_local(i32* %a, i32 %b) {
262 ; RV32I-LABEL: lw_sw_far_local:
264 ; RV32I-NEXT: lui a2, 4
265 ; RV32I-NEXT: add a2, a0, a2
266 ; RV32I-NEXT: lw a0, -4(a2)
267 ; RV32I-NEXT: sw a1, -4(a2)
269 %1 = getelementptr inbounds i32, i32* %a, i64 4095
270 %2 = load volatile i32, i32* %1
271 store i32 %b, i32* %1
275 define i32 @lw_really_far_local(i32* %a) {
276 ; RV32I-LABEL: lw_really_far_local:
278 ; RV32I-NEXT: lui a1, 524288
279 ; RV32I-NEXT: add a0, a0, a1
280 ; RV32I-NEXT: lw a0, -2048(a0)
282 %1 = getelementptr inbounds i32, i32* %a, i32 536870400
283 %2 = load volatile i32, i32* %1
287 define void @st_really_far_local(i32* %a, i32 %b) {
288 ; RV32I-LABEL: st_really_far_local:
290 ; RV32I-NEXT: lui a2, 524288
291 ; RV32I-NEXT: add a0, a0, a2
292 ; RV32I-NEXT: sw a1, -2048(a0)
294 %1 = getelementptr inbounds i32, i32* %a, i32 536870400
295 store i32 %b, i32* %1
299 define i32 @lw_sw_really_far_local(i32* %a, i32 %b) {
300 ; RV32I-LABEL: lw_sw_really_far_local:
302 ; RV32I-NEXT: lui a2, 524288
303 ; RV32I-NEXT: add a2, a0, a2
304 ; RV32I-NEXT: lw a0, -2048(a2)
305 ; RV32I-NEXT: sw a1, -2048(a2)
307 %1 = getelementptr inbounds i32, i32* %a, i32 536870400
308 %2 = load volatile i32, i32* %1
309 store i32 %b, i32* %1
313 %struct.quux = type { i32, [0 x i8] }
315 ; Make sure we don't remove the addi and fold the C from
316 ; (add (addi FrameIndex, C), X) into the store address.
317 ; FrameIndex cannot be the operand of an ADD. We must keep the ADDI.
318 define void @addi_fold_crash(i32 %arg) nounwind {
319 ; RV32I-LABEL: addi_fold_crash:
320 ; RV32I: # %bb.0: # %bb
321 ; RV32I-NEXT: addi sp, sp, -16
322 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
323 ; RV32I-NEXT: addi a1, sp, 12
324 ; RV32I-NEXT: add a0, a1, a0
325 ; RV32I-NEXT: sb zero, 0(a0)
326 ; RV32I-NEXT: mv a0, a1
327 ; RV32I-NEXT: call snork@plt
328 ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
329 ; RV32I-NEXT: addi sp, sp, 16
332 %tmp = alloca %struct.quux, align 4
333 %tmp1 = getelementptr inbounds %struct.quux, %struct.quux* %tmp, i32 0, i32 1
334 %tmp2 = getelementptr inbounds %struct.quux, %struct.quux* %tmp, i32 0, i32 1, i32 %arg
335 store i8 0, i8* %tmp2, align 1
336 call void @snork([0 x i8]* %tmp1)
340 declare void @snork([0 x i8]*)