Skip to content

Commit 9afa5b8

Browse files
committed
[RISCV] Add tests for (load (add X, [2048,4094])). NFC
Offsets in the range [-4095,-2049] or [2048, 4094] are split into two ADDIs. One of the ADDIs will be folded into the load/store immediate through an post-isel peephole.
1 parent 20dd329 commit 9afa5b8

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

llvm/test/CodeGen/RISCV/mem.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,41 @@ define dso_local i32 @lw_sw_constant(i32 %a) nounwind {
199199
ret i32 %2
200200
}
201201

202+
define i32 @lw_near_local(i32* %a) {
203+
; RV32I-LABEL: lw_near_local:
204+
; RV32I: # %bb.0:
205+
; RV32I-NEXT: addi a0, a0, 2047
206+
; RV32I-NEXT: lw a0, 5(a0)
207+
; RV32I-NEXT: ret
208+
%1 = getelementptr inbounds i32, i32* %a, i64 513
209+
%2 = load volatile i32, i32* %1
210+
ret i32 %2
211+
}
212+
213+
define void @st_near_local(i32* %a, i32 %b) {
214+
; RV32I-LABEL: st_near_local:
215+
; RV32I: # %bb.0:
216+
; RV32I-NEXT: addi a0, a0, 2047
217+
; RV32I-NEXT: sw a1, 5(a0)
218+
; RV32I-NEXT: ret
219+
%1 = getelementptr inbounds i32, i32* %a, i64 513
220+
store i32 %b, i32* %1
221+
ret void
222+
}
223+
224+
define i32 @lw_sw_near_local(i32* %a, i32 %b) {
225+
; RV32I-LABEL: lw_sw_near_local:
226+
; RV32I: # %bb.0:
227+
; RV32I-NEXT: addi a2, a0, 2047
228+
; RV32I-NEXT: lw a0, 5(a2)
229+
; RV32I-NEXT: sw a1, 5(a2)
230+
; RV32I-NEXT: ret
231+
%1 = getelementptr inbounds i32, i32* %a, i64 513
232+
%2 = load volatile i32, i32* %1
233+
store i32 %b, i32* %1
234+
ret i32 %2
235+
}
236+
202237
define i32 @lw_far_local(i32* %a) {
203238
; RV32I-LABEL: lw_far_local:
204239
; RV32I: # %bb.0:

llvm/test/CodeGen/RISCV/mem64.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,41 @@ define dso_local i64 @ld_sd_global(i64 %a) nounwind {
229229
ret i64 %1
230230
}
231231

232+
define i64 @lw_near_local(i64* %a) {
233+
; RV64I-LABEL: lw_near_local:
234+
; RV64I: # %bb.0:
235+
; RV64I-NEXT: addi a0, a0, 2047
236+
; RV64I-NEXT: ld a0, 9(a0)
237+
; RV64I-NEXT: ret
238+
%1 = getelementptr inbounds i64, i64* %a, i64 257
239+
%2 = load volatile i64, i64* %1
240+
ret i64 %2
241+
}
242+
243+
define void @st_near_local(i64* %a, i64 %b) {
244+
; RV64I-LABEL: st_near_local:
245+
; RV64I: # %bb.0:
246+
; RV64I-NEXT: addi a0, a0, 2047
247+
; RV64I-NEXT: sd a1, 9(a0)
248+
; RV64I-NEXT: ret
249+
%1 = getelementptr inbounds i64, i64* %a, i64 257
250+
store i64 %b, i64* %1
251+
ret void
252+
}
253+
254+
define i64 @lw_sw_near_local(i64* %a, i64 %b) {
255+
; RV64I-LABEL: lw_sw_near_local:
256+
; RV64I: # %bb.0:
257+
; RV64I-NEXT: addi a2, a0, 2047
258+
; RV64I-NEXT: ld a0, 9(a2)
259+
; RV64I-NEXT: sd a1, 9(a2)
260+
; RV64I-NEXT: ret
261+
%1 = getelementptr inbounds i64, i64* %a, i64 257
262+
%2 = load volatile i64, i64* %1
263+
store i64 %b, i64* %1
264+
ret i64 %2
265+
}
266+
232267
define i64 @lw_far_local(i64* %a) {
233268
; RV64I-LABEL: lw_far_local:
234269
; RV64I: # %bb.0:

0 commit comments

Comments
 (0)