1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
4 target datalayout = "E-m:e-p:32:32-i64:32-f64:32:64-a:0:32-n32-S32"
6 %struct.ilist = type { i32, %struct.ilist* }
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.
11 define %struct.ilist* @test() {
13 ; CHECK-NEXT: br label [[LOOP:%.*]]
15 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[TMP0:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
16 ; CHECK-NEXT: [[LIST_NEXT:%.*]] = phi %struct.ilist* [ null, [[TMP0]] ], [ [[LIST_NEW_ILIST_PTR:%.*]], [[LOOP]] ]
17 ; CHECK-NEXT: [[LIST_NEW_I8_PTR:%.*]] = tail call align 8 dereferenceable_or_null(8) i8* @malloc(i32 8)
18 ; CHECK-NEXT: [[LIST_NEW_ILIST_PTR]] = bitcast i8* [[LIST_NEW_I8_PTR]] to %struct.ilist*
19 ; CHECK-NEXT: [[GEP_NEW_VALUE:%.*]] = getelementptr inbounds [[STRUCT_ILIST:%.*]], %struct.ilist* [[LIST_NEW_ILIST_PTR]], i32 0, i32 0
20 ; CHECK-NEXT: store i32 42, i32* [[GEP_NEW_VALUE]], align 8
21 ; CHECK-NEXT: [[GEP_NEW_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_NEW_ILIST_PTR]], i32 0, i32 1
22 ; CHECK-NEXT: store %struct.ilist* [[LIST_NEXT]], %struct.ilist** [[GEP_NEW_NEXT]], align 4
23 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
24 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], 10
25 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
27 ; CHECK-NEXT: [[LIST_LAST_ILIST_PTR:%.*]] = bitcast i8* [[LIST_NEW_I8_PTR]] to %struct.ilist*
28 ; CHECK-NEXT: [[GEP_LIST_LAST_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_LAST_ILIST_PTR]], i32 0, i32 1
29 ; CHECK-NEXT: store %struct.ilist* null, %struct.ilist** [[GEP_LIST_LAST_NEXT]], align 4
30 ; CHECK-NEXT: [[GEP_LIST_NEXT_NEXT:%.*]] = getelementptr inbounds [[STRUCT_ILIST]], %struct.ilist* [[LIST_NEXT]], i32 0, i32 1
31 ; CHECK-NEXT: [[LOADED_PTR:%.*]] = load %struct.ilist*, %struct.ilist** [[GEP_LIST_NEXT_NEXT]], align 4
32 ; CHECK-NEXT: ret %struct.ilist* [[LOADED_PTR]]
37 %iv = phi i32 [ 0, %0 ], [ %iv.next, %loop ]
38 %list.next = phi %struct.ilist* [ null, %0 ], [ %list.new.ilist.ptr, %loop ]
39 %list.new.i8.ptr = tail call align 8 dereferenceable_or_null(8) i8* @malloc(i32 8)
40 %list.new.ilist.ptr = bitcast i8* %list.new.i8.ptr to %struct.ilist*
41 %gep.new.value = getelementptr inbounds %struct.ilist, %struct.ilist* %list.new.ilist.ptr, i32 0, i32 0
42 store i32 42, i32* %gep.new.value, align 8
43 %gep.new.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.new.ilist.ptr, i32 0, i32 1
44 store %struct.ilist* %list.next, %struct.ilist** %gep.new.next, align 4
45 %iv.next = add nuw nsw i32 %iv, 1
46 %cond = icmp eq i32 %iv.next, 10
47 br i1 %cond, label %exit, label %loop
50 %list.last.ilist.ptr = bitcast i8* %list.new.i8.ptr to %struct.ilist*
51 %gep.list.last.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.last.ilist.ptr, i32 0, i32 1
52 store %struct.ilist* null, %struct.ilist** %gep.list.last.next, align 4
53 %gep.list.next.next = getelementptr inbounds %struct.ilist, %struct.ilist* %list.next, i32 0, i32 1
54 %loaded_ptr = load %struct.ilist*, %struct.ilist** %gep.list.next.next, align 4
55 ret %struct.ilist* %loaded_ptr ; use loaded pointer
58 ; Function Attrs: inaccessiblememonly nounwind
59 declare noalias noundef align 8 i8* @malloc(i32 noundef) local_unnamed_addr #0
61 attributes #0 = { inaccessiblememonly nounwind}