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(ptr %a) nounwind {
10 ; RV32I-NEXT: lb a1, 1(a0)
11 ; RV32I-NEXT: lbu zero, 0(a0)
12 ; RV32I-NEXT: mv a0, a1
14 %1 = getelementptr i8, ptr %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, ptr %a
22 define dso_local i32 @lh(ptr %a) nounwind {
25 ; RV32I-NEXT: lh a1, 4(a0)
26 ; RV32I-NEXT: lh zero, 0(a0)
27 ; RV32I-NEXT: mv a0, a1
29 %1 = getelementptr i16, ptr %a, i32 2
31 %3 = sext i16 %2 to i32
32 ; the unused load will produce an anyext for selection
33 %4 = load volatile i16, ptr %a
37 define dso_local i32 @lw(ptr %a) nounwind {
40 ; RV32I-NEXT: lw a1, 12(a0)
41 ; RV32I-NEXT: lw zero, 0(a0)
42 ; RV32I-NEXT: mv a0, a1
44 %1 = getelementptr i32, ptr %a, i32 3
46 %3 = load volatile i32, ptr %a
50 define dso_local i32 @lbu(ptr %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, ptr %a, i32 4
59 %3 = zext i8 %2 to i32
60 %4 = load volatile i8, ptr %a
61 %5 = zext i8 %4 to i32
66 define dso_local i32 @lhu(ptr %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, ptr %a, i32 5
75 %3 = zext i16 %2 to i32
76 %4 = load volatile i16, ptr %a
77 %5 = zext i16 %4 to i32
82 ; Check indexed and unindexed stores
84 define dso_local void @sb(ptr %a, i8 %b) nounwind {
87 ; RV32I-NEXT: sb a1, 0(a0)
88 ; RV32I-NEXT: sb a1, 6(a0)
91 %1 = getelementptr i8, ptr %a, i32 6
96 define dso_local void @sh(ptr %a, i16 %b) nounwind {
99 ; RV32I-NEXT: sh a1, 0(a0)
100 ; RV32I-NEXT: sh a1, 14(a0)
103 %1 = getelementptr i16, ptr %a, i32 7
108 define dso_local void @sw(ptr %a, i32 %b) nounwind {
111 ; RV32I-NEXT: sw a1, 0(a0)
112 ; RV32I-NEXT: sw a1, 32(a0)
115 %1 = getelementptr i32, ptr %a, i32 8
120 ; Check load and store to an i1 location
121 define dso_local i32 @load_sext_zext_anyext_i1(ptr %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: lbu zero, 0(a0)
127 ; RV32I-NEXT: sub a0, a2, a1
130 %1 = getelementptr i1, ptr %a, i32 1
132 %3 = sext i1 %2 to i32
134 %4 = getelementptr i1, ptr %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, ptr %a
143 define dso_local i16 @load_sext_zext_anyext_i1_i16(ptr %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: lbu zero, 0(a0)
149 ; RV32I-NEXT: sub a0, a2, a1
152 %1 = getelementptr i1, ptr %a, i32 1
154 %3 = sext i1 %2 to i16
156 %4 = getelementptr i1, ptr %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, ptr %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 zero, 36(a3)
176 ; RV32I-NEXT: sw a0, 36(a3)
177 ; RV32I-NEXT: mv a0, a1
179 %1 = load volatile i32, ptr @G
181 %2 = getelementptr i32, ptr @G, i32 9
182 %3 = load volatile i32, ptr %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 ptr
197 %2 = load volatile i32, ptr %1
202 define i32 @lw_near_local(ptr %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, ptr %a, i64 513
209 %2 = load volatile i32, ptr %1
213 define void @st_near_local(ptr %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, ptr %a, i64 513
224 define i32 @lw_sw_near_local(ptr %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, ptr %a, i64 513
232 %2 = load volatile i32, ptr %1
237 define i32 @lw_far_local(ptr %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, ptr %a, i64 4095
245 %2 = load volatile i32, ptr %1
249 define void @st_far_local(ptr %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, ptr %a, i64 4095
261 define i32 @lw_sw_far_local(ptr %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, ptr %a, i64 4095
270 %2 = load volatile i32, ptr %1
275 define i32 @lw_really_far_local(ptr %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, ptr %a, i32 536870400
283 %2 = load volatile i32, ptr %1
287 define void @st_really_far_local(ptr %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, ptr %a, i32 536870400
299 define i32 @lw_sw_really_far_local(ptr %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, ptr %a, i32 536870400
308 %2 = load volatile i32, ptr %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
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, ptr %tmp, i32 0, i32 1
334 %tmp2 = getelementptr inbounds %struct.quux, ptr %tmp, i32 0, i32 1, i32 %arg
335 store i8 0, ptr %tmp2, align 1
336 call void @snork(ptr %tmp1)
340 declare void @snork(ptr)
342 define i8 @disjoint_or_lb(ptr %a, i32 %off) nounwind {
343 ; RV32I-LABEL: disjoint_or_lb:
345 ; RV32I-NEXT: add a0, a0, a1
346 ; RV32I-NEXT: lbu a0, 3(a0)
348 %b = or disjoint i32 %off, 3
349 %1 = getelementptr i8, ptr %a, i32 %b
354 define i32 @disjoint_or_lw(ptr %a, i32 %off) nounwind {
355 ; RV32I-LABEL: disjoint_or_lw:
357 ; RV32I-NEXT: slli a1, a1, 2
358 ; RV32I-NEXT: add a0, a0, a1
359 ; RV32I-NEXT: lw a0, 12(a0)
361 %b = or disjoint i32 %off, 3
362 %1 = getelementptr i32, ptr %a, i32 %b
363 %2 = load i32, ptr %1