Skip to content

Commit fb581ad

Browse files
committed
[SROA] Add tests with gep of index select (NFC)
1 parent 89ad31f commit fb581ad

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

llvm/test/Transforms/SROA/select-gep.ll

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,116 @@ bb:
154154
%load = load i32, ptr %gep, align 4
155155
ret i32 %load
156156
}
157+
158+
159+
define i32 @test_select_idx_memcpy(i1 %c, ptr %p) {
160+
; CHECK-LABEL: @test_select_idx_memcpy(
161+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
162+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[ALLOCA]], ptr [[P:%.*]], i64 160, i1 false)
163+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 0
164+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
165+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP]], align 4
166+
; CHECK-NEXT: ret i32 [[RES]]
167+
;
168+
%alloca = alloca [20 x i64], align 8
169+
call void @llvm.memcpy.p0.p0.i64(ptr %alloca, ptr %p, i64 160, i1 false)
170+
%idx = select i1 %c, i64 24, i64 0
171+
%gep = getelementptr inbounds i8, ptr %alloca, i64 %idx
172+
%res = load i32, ptr %gep, align 4
173+
ret i32 %res
174+
}
175+
176+
define i32 @test_select_idx_mem2reg(i1 %c) {
177+
; CHECK-LABEL: @test_select_idx_mem2reg(
178+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
179+
; CHECK-NEXT: store i32 1, ptr [[ALLOCA]], align 4
180+
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 24
181+
; CHECK-NEXT: store i32 2, ptr [[GEP1]], align 4
182+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 0
183+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
184+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP2]], align 4
185+
; CHECK-NEXT: ret i32 [[RES]]
186+
;
187+
%alloca = alloca [20 x i64], align 8
188+
store i32 1, ptr %alloca
189+
%gep1 = getelementptr inbounds i8, ptr %alloca, i64 24
190+
store i32 2, ptr %gep1
191+
%idx = select i1 %c, i64 24, i64 0
192+
%gep2 = getelementptr inbounds i8, ptr %alloca, i64 %idx
193+
%res = load i32, ptr %gep2, align 4
194+
ret i32 %res
195+
}
196+
197+
define i32 @test_select_idx_escaped(i1 %c, ptr %p) {
198+
; CHECK-LABEL: @test_select_idx_escaped(
199+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
200+
; CHECK-NEXT: store ptr [[ALLOCA]], ptr [[P:%.*]], align 8
201+
; CHECK-NEXT: store i32 1, ptr [[ALLOCA]], align 4
202+
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 24
203+
; CHECK-NEXT: store i32 2, ptr [[GEP1]], align 4
204+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 0
205+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
206+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP2]], align 4
207+
; CHECK-NEXT: ret i32 [[RES]]
208+
;
209+
%alloca = alloca [20 x i64], align 8
210+
store ptr %alloca, ptr %p
211+
store i32 1, ptr %alloca
212+
%gep1 = getelementptr inbounds i8, ptr %alloca, i64 24
213+
store i32 2, ptr %gep1
214+
%idx = select i1 %c, i64 24, i64 0
215+
%gep2 = getelementptr inbounds i8, ptr %alloca, i64 %idx
216+
%res = load i32, ptr %gep2, align 4
217+
ret i32 %res
218+
}
219+
220+
define i32 @test_select_idx_not_constant1(i1 %c, ptr %p, i64 %arg) {
221+
; CHECK-LABEL: @test_select_idx_not_constant1(
222+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
223+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[ALLOCA]], ptr [[P:%.*]], i64 160, i1 false)
224+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 [[ARG:%.*]]
225+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
226+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP]], align 4
227+
; CHECK-NEXT: ret i32 [[RES]]
228+
;
229+
%alloca = alloca [20 x i64], align 8
230+
call void @llvm.memcpy.p0.p0.i64(ptr %alloca, ptr %p, i64 160, i1 false)
231+
%idx = select i1 %c, i64 24, i64 %arg
232+
%gep = getelementptr inbounds i8, ptr %alloca, i64 %idx
233+
%res = load i32, ptr %gep, align 4
234+
ret i32 %res
235+
}
236+
237+
define i32 @test_select_idx_not_constant2(i1 %c, ptr %p, i64 %arg) {
238+
; CHECK-LABEL: @test_select_idx_not_constant2(
239+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
240+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[ALLOCA]], ptr [[P:%.*]], i64 160, i1 false)
241+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 [[ARG:%.*]], i64 0
242+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[ALLOCA]], i64 [[IDX]]
243+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP]], align 4
244+
; CHECK-NEXT: ret i32 [[RES]]
245+
;
246+
%alloca = alloca [20 x i64], align 8
247+
call void @llvm.memcpy.p0.p0.i64(ptr %alloca, ptr %p, i64 160, i1 false)
248+
%idx = select i1 %c, i64 %arg, i64 0
249+
%gep = getelementptr inbounds i8, ptr %alloca, i64 %idx
250+
%res = load i32, ptr %gep, align 4
251+
ret i32 %res
252+
}
253+
254+
define i32 @test_select_idx_not_constant3(i1 %c, ptr %p, i64 %arg) {
255+
; CHECK-LABEL: @test_select_idx_not_constant3(
256+
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [20 x i64], align 8
257+
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[ALLOCA]], ptr [[P:%.*]], i64 160, i1 false)
258+
; CHECK-NEXT: [[IDX:%.*]] = select i1 [[C:%.*]], i64 24, i64 0
259+
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [1 x i8], ptr [[ALLOCA]], i64 [[IDX]], i64 [[ARG:%.*]]
260+
; CHECK-NEXT: [[RES:%.*]] = load i32, ptr [[GEP]], align 4
261+
; CHECK-NEXT: ret i32 [[RES]]
262+
;
263+
%alloca = alloca [20 x i64], align 8
264+
call void @llvm.memcpy.p0.p0.i64(ptr %alloca, ptr %p, i64 160, i1 false)
265+
%idx = select i1 %c, i64 24, i64 0
266+
%gep = getelementptr inbounds [1 x i8], ptr %alloca, i64 %idx, i64 %arg
267+
%res = load i32, ptr %gep, align 4
268+
ret i32 %res
269+
}

0 commit comments

Comments
 (0)