Skip to content

Commit 3d5179f

Browse files
committed
[DSE] Add additional tests for noalias calls (NFC)
Currently this is special-cased to TLI alloc functions only.
1 parent 41fbdfa commit 3d5179f

File tree

1 file changed

+42
-9
lines changed
  • llvm/test/Transforms/DeadStoreElimination

1 file changed

+42
-9
lines changed

llvm/test/Transforms/DeadStoreElimination/simple.ll

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ define void @test_matrix_store(i64 %stride) {
206206
}
207207

208208
; %P doesn't escape, the DEAD instructions should be removed.
209-
declare void @test13f()
210-
define i32* @test13() {
211-
; CHECK-LABEL: @test13(
209+
declare void @may_unwind()
210+
define i32* @test_malloc_no_escape_before_return() {
211+
; CHECK-LABEL: @test_malloc_no_escape_before_return(
212212
; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @malloc(i32 4)
213213
; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
214-
; CHECK-NEXT: call void @test13f()
214+
; CHECK-NEXT: call void @may_unwind()
215215
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
216216
; CHECK-NEXT: ret i32* [[P]]
217217
;
@@ -220,7 +220,28 @@ define i32* @test13() {
220220
%DEAD = load i32, i32* %P
221221
%DEAD2 = add i32 %DEAD, 1
222222
store i32 %DEAD2, i32* %P
223-
call void @test13f( )
223+
call void @may_unwind()
224+
store i32 0, i32* %P
225+
ret i32* %P
226+
}
227+
228+
define i32* @test_custom_malloc_no_escape_before_return() {
229+
; CHECK-LABEL: @test_custom_malloc_no_escape_before_return(
230+
; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @custom_malloc(i32 4)
231+
; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
232+
; CHECK-NEXT: [[DEAD:%.*]] = load i32, i32* [[P]], align 4
233+
; CHECK-NEXT: [[DEAD2:%.*]] = add i32 [[DEAD]], 1
234+
; CHECK-NEXT: store i32 [[DEAD2]], i32* [[P]], align 4
235+
; CHECK-NEXT: call void @may_unwind()
236+
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
237+
; CHECK-NEXT: ret i32* [[P]]
238+
;
239+
%ptr = tail call i8* @custom_malloc(i32 4)
240+
%P = bitcast i8* %ptr to i32*
241+
%DEAD = load i32, i32* %P
242+
%DEAD2 = add i32 %DEAD, 1
243+
store i32 %DEAD2, i32* %P
244+
call void @may_unwind()
224245
store i32 0, i32* %P
225246
ret i32* %P
226247
}
@@ -230,7 +251,7 @@ define i32 addrspace(1)* @test13_addrspacecast() {
230251
; CHECK-NEXT: [[P:%.*]] = tail call i8* @malloc(i32 4)
231252
; CHECK-NEXT: [[P_BC:%.*]] = bitcast i8* [[P]] to i32*
232253
; CHECK-NEXT: [[P:%.*]] = addrspacecast i32* [[P_BC]] to i32 addrspace(1)*
233-
; CHECK-NEXT: call void @test13f()
254+
; CHECK-NEXT: call void @may_unwind()
234255
; CHECK-NEXT: store i32 0, i32 addrspace(1)* [[P]], align 4
235256
; CHECK-NEXT: ret i32 addrspace(1)* [[P]]
236257
;
@@ -240,13 +261,14 @@ define i32 addrspace(1)* @test13_addrspacecast() {
240261
%DEAD = load i32, i32 addrspace(1)* %P
241262
%DEAD2 = add i32 %DEAD, 1
242263
store i32 %DEAD2, i32 addrspace(1)* %P
243-
call void @test13f( )
264+
call void @may_unwind()
244265
store i32 0, i32 addrspace(1)* %P
245266
ret i32 addrspace(1)* %P
246267
}
247268

248269

249270
declare noalias i8* @malloc(i32) willreturn
271+
declare noalias i8* @custom_malloc(i32) willreturn
250272
declare noalias i8* @calloc(i32, i32) willreturn
251273

252274
define void @test14(i32* %Q) {
@@ -279,15 +301,26 @@ bb:
279301

280302
}
281303

282-
define void @test20() {
283-
; CHECK-LABEL: @test20(
304+
define void @malloc_no_escape() {
305+
; CHECK-LABEL: @malloc_no_escape(
284306
; CHECK-NEXT: ret void
285307
;
286308
%m = call i8* @malloc(i32 24)
287309
store i8 0, i8* %m
288310
ret void
289311
}
290312

313+
define void @custom_malloc_no_escape() {
314+
; CHECK-LABEL: @custom_malloc_no_escape(
315+
; CHECK-NEXT: [[M:%.*]] = call i8* @custom_malloc(i32 24)
316+
; CHECK-NEXT: store i8 0, i8* [[M]], align 1
317+
; CHECK-NEXT: ret void
318+
;
319+
%m = call i8* @custom_malloc(i32 24)
320+
store i8 0, i8* %m
321+
ret void
322+
}
323+
291324
define void @test21() {
292325
; CHECK-LABEL: @test21(
293326
; CHECK-NEXT: ret void

0 commit comments

Comments
 (0)