Skip to content

Commit df59056

Browse files
committed
[DSE] Add test case showing bug PR52774.
Pre-commiting the test case before the bug fix. Reviewed by: Florian Hahn Differential revision: https://reviews.llvm.org/D115965
1 parent ad761f0 commit df59056

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -passes=dse -S | FileCheck %s
3+
4+
target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S32"
5+
6+
%struct.ilist = type { i32, %struct.ilist* }
7+
8+
; There is no dead store in this test. Make sure no store is deleted by DSE.
9+
; Test case related to bug report PR52774.
10+
; NOTE: Showing actual (broken) DSE behavior.
11+
12+
define %struct.ilist* @test() {
13+
; CHECK-LABEL: @test(
14+
; CHECK-NEXT: br label [[LOOP:%.*]]
15+
; CHECK: loop:
16+
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
17+
; CHECK-NEXT: [[LIST_NEXT:%.*]] = phi %struct.ilist* [ null, [[TMP0]] ], [ [[LIST_NEW_ILIST_PTR:%.*]], [[LOOP]] ]
18+
; CHECK-NEXT: [[LIST_NEW_I8_PTR:%.*]] = tail call align 8 dereferenceable_or_null(8) i8* @malloc(i32 8)
19+
; CHECK-NEXT: [[LIST_NEW_ILIST_PTR]] = bitcast i8* [[LIST_NEW_I8_PTR]] to %struct.ilist*
20+
; CHECK-NEXT: [[GEP_NEW_VALUE:%.*]] = getelementptr inbounds [[STRUCT_ILIST:%.*]], %struct.ilist* [[LIST_NEW_ILIST_PTR]], i32 0, i32 0
21+
; CHECK-NEXT: store i32 42, i32* [[GEP_NEW_VALUE]], align 8
22+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
23+
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], 10
24+
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
25+
; CHECK: exit:
26+
; CHECK-NEXT: [[LIST_LAST_ILIST_PTR:%.*]] = bitcast i8* [[LIST_NEW_I8_PTR]] to %struct.ilist*
27+
; CHECK-NEXT: [[GEP_LIST_LAST_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_LAST_ILIST_PTR]], i32 0, i32 1
28+
; CHECK-NEXT: store %struct.ilist* null, %struct.ilist** [[GEP_LIST_LAST_NEXT]], align 4
29+
; CHECK-NEXT: [[GEP_LIST_NEXT_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_NEXT]], i32 0, i32 1
30+
; CHECK-NEXT: [[LOADED_PTR:%.*]] = load %struct.ilist*, %struct.ilist** [[GEP_LIST_NEXT_NEXT]], align 4
31+
; CHECK-NEXT: ret %struct.ilist* [[LOADED_PTR]]
32+
;
33+
br label %loop
34+
35+
loop:
36+
%iv = phi i32 [ 0, %0 ], [ %iv.next, %loop ]
37+
%list.next = phi %struct.ilist* [ null, %0 ], [ %list.new.ilist.ptr, %loop ]
38+
%list.new.i8.ptr = tail call align 8 dereferenceable_or_null(8) i8* @malloc(i32 8)
39+
%list.new.ilist.ptr = bitcast i8* %list.new.i8.ptr to %struct.ilist*
40+
%gep.new.value = getelementptr inbounds %struct.ilist, %struct.ilist* %list.new.ilist.ptr, i32 0, i32 0
41+
store i32 42, i32* %gep.new.value, align 8
42+
%gep.new.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.new.ilist.ptr, i32 0, i32 1
43+
store %struct.ilist* %list.next, %struct.ilist** %gep.new.next, align 4
44+
%iv.next = add nuw nsw i32 %iv, 1
45+
%cond = icmp eq i32 %iv.next, 10
46+
br i1 %cond, label %exit, label %loop
47+
48+
exit:
49+
%list.last.ilist.ptr = bitcast i8* %list.new.i8.ptr to %struct.ilist*
50+
%gep.list.last.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.last.ilist.ptr, i32 0, i32 1
51+
store %struct.ilist* null, %struct.ilist** %gep.list.last.next, align 4
52+
%gep.list.next.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.next, i32 0, i32 1
53+
%loaded_ptr = load %struct.ilist*, %struct.ilist** %gep.list.next.next, align 4
54+
ret %struct.ilist* %loaded_ptr ; use loaded pointer
55+
}
56+
57+
; Function Attrs: inaccessiblememonly nounwind
58+
declare noalias noundef align 8 i8* @malloc(i32 noundef) local_unnamed_addr #0
59+
60+
attributes #0 = { inaccessiblememonly nounwind}

0 commit comments

Comments
 (0)