Skip to content

Commit fe369c1

Browse files
badumbatishbadumbatish
authored andcommitted
Precommit test for folding a load of unsigned offset
1 parent 532c15a commit fe369c1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

llvm/test/CodeGen/WebAssembly/offset.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ define i32 @load_i32_with_folded_gep_offset_nuw(ptr %p) {
6060
ret i32 %t
6161
}
6262

63+
@global_data = hidden local_unnamed_addr global [12 x i8] c"Hello world\00", align 1
64+
65+
define hidden signext i8 @global_load_i32_with_folded_gep_offset_nonconst_nuw(i32 noundef %idx) local_unnamed_addr {
66+
; CHECK-LABEL: global_load_i32_with_folded_gep_offset_nonconst_nuw:
67+
; CHECK: .functype global_load_i32_with_folded_gep_offset_nonconst_nuw (i32) -> (i32)
68+
; CHECK: i32.const $push0=, global_data
69+
; CHECK: i32.add $push1=, $0, $pop0
70+
; CHECK: i32.load8_s $push2=, 0($pop1)
71+
; CHECK: return $pop2
72+
entry:
73+
%arrayidx = getelementptr inbounds nuw [12 x i8], ptr @global_data, i32 0, i32 %idx
74+
%0 = load i8, ptr %arrayidx, align 1
75+
ret i8 %0
76+
}
77+
78+
define hidden signext i8 @global_load_i32_with_folded_gep_offset_const_nuw() local_unnamed_addr {
79+
; CHECK-LABEL: global_load_i32_with_folded_gep_offset_const_nuw:
80+
; CHECK: .functype global_load_i32_with_folded_gep_offset_const_nuw () -> (i32)
81+
; CHECK: i32.const $push0=, 0
82+
; CHECK: i32.load8_s $push1=, global_data+2($pop0)
83+
; CHECK: return $pop1
84+
entry:
85+
%0 = load i8, ptr getelementptr inbounds nuw (i8, ptr @global_data, i32 2), align 1
86+
ret i8 %0
87+
}
88+
89+
6390
; We can't fold a negative offset though, even with an inbounds gep.
6491

6592
; CHECK-LABEL: load_i32_with_unfolded_gep_negative_offset:

0 commit comments

Comments
 (0)