1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck -check-prefix=RV64I %s
5 ; Check indexed and unindexed, sext, zext and anyext loads
7 define dso_local i64 @lb(ptr %a) nounwind {
10 ; RV64I-NEXT: lb a1, 1(a0)
11 ; RV64I-NEXT: lbu zero, 0(a0)
12 ; RV64I-NEXT: mv a0, a1
14 %1 = getelementptr i8, ptr %a, i32 1
16 %3 = sext i8 %2 to i64
17 ; the unused load will produce an anyext for selection
18 %4 = load volatile i8, ptr %a
22 define dso_local i64 @lh(ptr %a) nounwind {
25 ; RV64I-NEXT: lh a1, 4(a0)
26 ; RV64I-NEXT: lh zero, 0(a0)
27 ; RV64I-NEXT: mv a0, a1
29 %1 = getelementptr i16, ptr %a, i32 2
31 %3 = sext i16 %2 to i64
32 ; the unused load will produce an anyext for selection
33 %4 = load volatile i16, ptr %a
37 define dso_local i64 @lw(ptr %a) nounwind {
40 ; RV64I-NEXT: lw a1, 12(a0)
41 ; RV64I-NEXT: lw zero, 0(a0)
42 ; RV64I-NEXT: mv a0, a1
44 %1 = getelementptr i32, ptr %a, i32 3
46 %3 = sext i32 %2 to i64
47 ; the unused load will produce an anyext for selection
48 %4 = load volatile i32, ptr %a
52 define dso_local i64 @lbu(ptr %a) nounwind {
55 ; RV64I-NEXT: lbu a1, 4(a0)
56 ; RV64I-NEXT: lbu a0, 0(a0)
57 ; RV64I-NEXT: add a0, a1, a0
59 %1 = getelementptr i8, ptr %a, i32 4
61 %3 = zext i8 %2 to i64
62 %4 = load volatile i8, ptr %a
63 %5 = zext i8 %4 to i64
68 define dso_local i64 @lhu(ptr %a) nounwind {
71 ; RV64I-NEXT: lhu a1, 10(a0)
72 ; RV64I-NEXT: lhu a0, 0(a0)
73 ; RV64I-NEXT: add a0, a1, a0
75 %1 = getelementptr i16, ptr %a, i32 5
77 %3 = zext i16 %2 to i64
78 %4 = load volatile i16, ptr %a
79 %5 = zext i16 %4 to i64
84 define dso_local i64 @lwu(ptr %a) nounwind {
87 ; RV64I-NEXT: lwu a1, 24(a0)
88 ; RV64I-NEXT: lwu a0, 0(a0)
89 ; RV64I-NEXT: add a0, a1, a0
91 %1 = getelementptr i32, ptr %a, i32 6
93 %3 = zext i32 %2 to i64
94 %4 = load volatile i32, ptr %a
95 %5 = zext i32 %4 to i64
100 ; 64-bit loads and stores
102 define dso_local i64 @ld(ptr %a) nounwind {
105 ; RV64I-NEXT: ld a1, 80(a0)
106 ; RV64I-NEXT: ld zero, 0(a0)
107 ; RV64I-NEXT: mv a0, a1
109 %1 = getelementptr i64, ptr %a, i32 10
110 %2 = load i64, ptr %1
111 %3 = load volatile i64, ptr %a
115 define dso_local void @sd(ptr %a, i64 %b) nounwind {
118 ; RV64I-NEXT: sd a1, 0(a0)
119 ; RV64I-NEXT: sd a1, 88(a0)
122 %1 = getelementptr i64, ptr %a, i32 11
127 ; Check load and store to an i1 location
128 define dso_local i64 @load_sext_zext_anyext_i1(ptr %a) nounwind {
129 ; RV64I-LABEL: load_sext_zext_anyext_i1:
131 ; RV64I-NEXT: lbu a1, 1(a0)
132 ; RV64I-NEXT: lbu a2, 2(a0)
133 ; RV64I-NEXT: lbu zero, 0(a0)
134 ; RV64I-NEXT: sub a0, a2, a1
137 %1 = getelementptr i1, ptr %a, i32 1
139 %3 = sext i1 %2 to i64
141 %4 = getelementptr i1, ptr %a, i32 2
143 %6 = zext i1 %5 to i64
145 ; extload i1 (anyext). Produced as the load is unused.
146 %8 = load volatile i1, ptr %a
150 define dso_local i16 @load_sext_zext_anyext_i1_i16(ptr %a) nounwind {
151 ; RV64I-LABEL: load_sext_zext_anyext_i1_i16:
153 ; RV64I-NEXT: lbu a1, 1(a0)
154 ; RV64I-NEXT: lbu a2, 2(a0)
155 ; RV64I-NEXT: lbu zero, 0(a0)
156 ; RV64I-NEXT: subw a0, a2, a1
159 %1 = getelementptr i1, ptr %a, i32 1
161 %3 = sext i1 %2 to i16
163 %4 = getelementptr i1, ptr %a, i32 2
165 %6 = zext i1 %5 to i16
167 ; extload i1 (anyext). Produced as the load is unused.
168 %8 = load volatile i1, ptr %a
172 ; Check load and store to a global
173 @G = dso_local global i64 0
175 define dso_local i64 @ld_sd_global(i64 %a) nounwind {
176 ; RV64I-LABEL: ld_sd_global:
178 ; RV64I-NEXT: lui a2, %hi(G)
179 ; RV64I-NEXT: ld a1, %lo(G)(a2)
180 ; RV64I-NEXT: addi a3, a2, %lo(G)
181 ; RV64I-NEXT: sd a0, %lo(G)(a2)
182 ; RV64I-NEXT: ld zero, 72(a3)
183 ; RV64I-NEXT: sd a0, 72(a3)
184 ; RV64I-NEXT: mv a0, a1
186 %1 = load volatile i64, ptr @G
188 %2 = getelementptr i64, ptr @G, i64 9
189 %3 = load volatile i64, ptr %2
194 define i64 @lw_near_local(ptr %a) {
195 ; RV64I-LABEL: lw_near_local:
197 ; RV64I-NEXT: addi a0, a0, 2047
198 ; RV64I-NEXT: ld a0, 9(a0)
200 %1 = getelementptr inbounds i64, ptr %a, i64 257
201 %2 = load volatile i64, ptr %1
205 define void @st_near_local(ptr %a, i64 %b) {
206 ; RV64I-LABEL: st_near_local:
208 ; RV64I-NEXT: addi a0, a0, 2047
209 ; RV64I-NEXT: sd a1, 9(a0)
211 %1 = getelementptr inbounds i64, ptr %a, i64 257
216 define i64 @lw_sw_near_local(ptr %a, i64 %b) {
217 ; RV64I-LABEL: lw_sw_near_local:
219 ; RV64I-NEXT: addi a2, a0, 2047
220 ; RV64I-NEXT: ld a0, 9(a2)
221 ; RV64I-NEXT: sd a1, 9(a2)
223 %1 = getelementptr inbounds i64, ptr %a, i64 257
224 %2 = load volatile i64, ptr %1
229 define i64 @lw_far_local(ptr %a) {
230 ; RV64I-LABEL: lw_far_local:
232 ; RV64I-NEXT: lui a1, 8
233 ; RV64I-NEXT: add a0, a0, a1
234 ; RV64I-NEXT: ld a0, -8(a0)
236 %1 = getelementptr inbounds i64, ptr %a, i64 4095
237 %2 = load volatile i64, ptr %1
241 define void @st_far_local(ptr %a, i64 %b) {
242 ; RV64I-LABEL: st_far_local:
244 ; RV64I-NEXT: lui a2, 8
245 ; RV64I-NEXT: add a0, a0, a2
246 ; RV64I-NEXT: sd a1, -8(a0)
248 %1 = getelementptr inbounds i64, ptr %a, i64 4095
253 define i64 @lw_sw_far_local(ptr %a, i64 %b) {
254 ; RV64I-LABEL: lw_sw_far_local:
256 ; RV64I-NEXT: lui a2, 8
257 ; RV64I-NEXT: add a2, a0, a2
258 ; RV64I-NEXT: ld a0, -8(a2)
259 ; RV64I-NEXT: sd a1, -8(a2)
261 %1 = getelementptr inbounds i64, ptr %a, i64 4095
262 %2 = load volatile i64, ptr %1
267 ; Make sure we don't fold the addiw into the load offset. The sign extend of the
269 define i64 @lw_really_far_local(ptr %a) {
270 ; RV64I-LABEL: lw_really_far_local:
272 ; RV64I-NEXT: lui a1, 524288
273 ; RV64I-NEXT: addiw a1, a1, -2048
274 ; RV64I-NEXT: add a0, a0, a1
275 ; RV64I-NEXT: ld a0, 0(a0)
277 %1 = getelementptr inbounds i64, ptr %a, i64 268435200
278 %2 = load volatile i64, ptr %1
282 ; Make sure we don't fold the addiw into the store offset. The sign extend of
283 ; the addiw is required.
284 define void @st_really_far_local(ptr %a, i64 %b) {
285 ; RV64I-LABEL: st_really_far_local:
287 ; RV64I-NEXT: lui a2, 524288
288 ; RV64I-NEXT: addiw a2, a2, -2048
289 ; RV64I-NEXT: add a0, a0, a2
290 ; RV64I-NEXT: sd a1, 0(a0)
292 %1 = getelementptr inbounds i64, ptr %a, i64 268435200
297 ; Make sure we don't fold the addiw into the load/store offset. The sign extend
298 ; of the addiw is required.
299 define i64 @lw_sw_really_far_local(ptr %a, i64 %b) {
300 ; RV64I-LABEL: lw_sw_really_far_local:
302 ; RV64I-NEXT: lui a2, 524288
303 ; RV64I-NEXT: addiw a2, a2, -2048
304 ; RV64I-NEXT: add a2, a0, a2
305 ; RV64I-NEXT: ld a0, 0(a2)
306 ; RV64I-NEXT: sd a1, 0(a2)
308 %1 = getelementptr inbounds i64, ptr %a, i64 268435200
309 %2 = load volatile i64, ptr %1
314 %struct.quux = type { i32, [0 x i8] }
316 ; Make sure we don't remove the addi and fold the C from
317 ; (add (addi FrameIndex, C), X) into the store address.
318 ; FrameIndex cannot be the operand of an ADD. We must keep the ADDI.
319 define void @addi_fold_crash(i64 %arg) nounwind {
320 ; RV64I-LABEL: addi_fold_crash:
321 ; RV64I: # %bb.0: # %bb
322 ; RV64I-NEXT: addi sp, sp, -16
323 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
324 ; RV64I-NEXT: addi a1, sp, 4
325 ; RV64I-NEXT: add a0, a1, a0
326 ; RV64I-NEXT: sb zero, 0(a0)
327 ; RV64I-NEXT: mv a0, a1
328 ; RV64I-NEXT: call snork@plt
329 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
330 ; RV64I-NEXT: addi sp, sp, 16
333 %tmp = alloca %struct.quux, align 8
334 %tmp1 = getelementptr inbounds %struct.quux, ptr %tmp, i64 0, i32 1
335 %tmp2 = getelementptr inbounds %struct.quux, ptr %tmp, i64 0, i32 1, i64 %arg
336 store i8 0, ptr %tmp2, align 1
337 call void @snork(ptr %tmp1)
341 declare void @snork(ptr)