llvm.org GIT mirror llvm / 6a6fa34
[DSE] Remove dead stores in end blocks containing fence We can remove dead stores in the presence of fence instructions. Fence does not change an otherwise thread local store to visible. reviewers: reames, dexonsmith, jfb Differential Revision: http://reviews.llvm.org/D22001 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274795 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Thomas 3 years ago
2 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
777777 continue;
778778 }
779779
780 // We can remove the dead stores, irrespective of the fence and its ordering
781 // (release/acquire/seq_cst). Fences only constraints the ordering of
782 // already visible stores, it does not make a store visible to other
783 // threads. So, skipping over a fence does not change a store from being
784 // dead.
785 if (isa(*BBI))
786 continue;
787
780788 MemoryLocation LoadedLoc;
781789
782790 // If we encounter a use of the pointer, it is no longer considered dead
4545 store i32 5, i32* %addr.i, align 4
4646 ret void
4747 }
48
49 ; We DSE stack alloc'ed and byval locations, in the presence of fences.
50 ; Fence does not make an otherwise thread local store visible.
51 ; Right now the DSE in presence of fence is only done in end blocks (with no successors),
52 ; but the same logic applies to other basic blocks as well.
53 ; The store to %addr.i can be removed since it is a byval attribute
54 define void @test3(i32* byval %addr.i) {
55 ; CHECK-LABEL: @test3
56 ; CHECK-NOT: store
57 ; CHECK: fence
58 ; CHECK: ret
59 store i32 5, i32* %addr.i, align 4
60 fence release
61 ret void
62 }
63
64 declare void @foo(i8* nocapture %p)
65
66 declare noalias i8* @malloc(i32)
67
68 ; DSE of stores in locations allocated through library calls.
69 define void @test_nocapture() {
70 ; CHECK-LABEL: @test_nocapture
71 ; CHECK: malloc
72 ; CHECK: foo
73 ; CHECK-NOT: store
74 ; CHECK: fence
75 %m = call i8* @malloc(i32 24)
76 call void @foo(i8* %m)
77 store i8 4, i8* %m
78 fence release
79 ret void
80 }
81
82
83 ; This is a full fence, but it does not make a thread local store visible.
84 ; We can DSE the store in presence of the fence.
85 define void @fence_seq_cst() {
86 ; CHECK-LABEL: @fence_seq_cst
87 ; CHECK-NEXT: fence seq_cst
88 ; CHECK-NEXT: ret void
89 %P1 = alloca i32
90 store i32 0, i32* %P1, align 4
91 fence seq_cst
92 store i32 4, i32* %P1, align 4
93 ret void
94 }
95