Skip to content

Commit f64d1c8

Browse files
committed
[RISCV] Add test cases for folding disjoint Or into a scalar load address. NFC
After 47a1704 we are able to reassociate a disjoint Or used as a GEP index to get the constant closer to a load to fold it. This is show by the first test. We are not able to do this if the GEP created a shift left to scale the index as the second test shows. To make this work, we need to preserve the disjoint flag when pulling the Or through the shift.
1 parent 47a1704 commit f64d1c8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

llvm/test/CodeGen/RISCV/mem.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,29 @@ bb:
338338
}
339339

340340
declare void @snork(ptr)
341+
342+
define i8 @disjoint_or_lb(ptr %a, i32 %off) nounwind {
343+
; RV32I-LABEL: disjoint_or_lb:
344+
; RV32I: # %bb.0:
345+
; RV32I-NEXT: add a0, a0, a1
346+
; RV32I-NEXT: lbu a0, 3(a0)
347+
; RV32I-NEXT: ret
348+
%b = or disjoint i32 %off, 3
349+
%1 = getelementptr i8, ptr %a, i32 %b
350+
%2 = load i8, ptr %1
351+
ret i8 %2
352+
}
353+
354+
define i32 @disjoint_or_lw(ptr %a, i32 %off) nounwind {
355+
; RV32I-LABEL: disjoint_or_lw:
356+
; RV32I: # %bb.0:
357+
; RV32I-NEXT: slli a1, a1, 2
358+
; RV32I-NEXT: ori a1, a1, 12
359+
; RV32I-NEXT: add a0, a0, a1
360+
; RV32I-NEXT: lw a0, 0(a0)
361+
; RV32I-NEXT: ret
362+
%b = or disjoint i32 %off, 3
363+
%1 = getelementptr i32, ptr %a, i32 %b
364+
%2 = load i32, ptr %1
365+
ret i32 %2
366+
}

0 commit comments

Comments
 (0)