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