1 ; RUN: opt -basicaa -dse -S < %s | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
4 target triple = "x86_64-apple-macosx10.7.0"
6 ; Sanity tests for atomic stores.
7 ; Note that it turns out essentially every transformation DSE does is legal on
8 ; atomic ops, just some transformations are not allowed across release-acquire pairs.
10 @x = common global i32 0, align 4
11 @y = common global i32 0, align 4
13 declare void @randomop(i32*)
15 ; DSE across unordered store (allowed)
16 define void @test1() {
18 ; CHECK-NOT: store i32 0
21 store atomic i32 0, i32* @y unordered, align 4
26 ; DSE across seq_cst load (allowed)
29 ; CHECK-NOT: store i32 0
32 %x = load atomic i32* @y seq_cst, align 4
37 ; DSE across seq_cst store (allowed)
38 define void @test3() {
40 ; CHECK-NOT: store i32 0
41 ; CHECK: store atomic i32 2
43 store atomic i32 2, i32* @y seq_cst, align 4
48 ; DSE remove unordered store (allowed)
49 define void @test4() {
51 ; CHECK-NOT: store atomic
53 store atomic i32 0, i32* @x unordered, align 4
58 ; DSE unordered store overwriting non-atomic store (allowed)
59 define void @test5() {
61 ; CHECK: store atomic i32 1
63 store atomic i32 1, i32* @x unordered, align 4
67 ; DSE no-op unordered atomic store (allowed)
68 define void @test6() {
72 %x = load atomic i32* @x unordered, align 4
73 store atomic i32 %x, i32* @x unordered, align 4
77 ; DSE seq_cst store (be conservative; DSE doesn't have infrastructure
78 ; to reason about atomic operations).
79 define void @test7() {
83 store atomic i32 0, i32* %a seq_cst, align 4
87 ; DSE and seq_cst load (be conservative; DSE doesn't have infrastructure
88 ; to reason about atomic operations).
94 call void @randomop(i32* %a)
95 store i32 0, i32* %a, align 4
96 %x = load atomic i32* @x seq_cst, align 4
100 ; DSE across monotonic load (allowed as long as the eliminated store isUnordered)
101 define i32 @test9() {
103 ; CHECK-NOT: store i32 0
106 %x = load atomic i32* @y monotonic, align 4
111 ; DSE across monotonic store (allowed as long as the eliminated store isUnordered)
112 define void @test10() {
113 ; CHECK-LABEL: test10
114 ; CHECK-NOT: store i32 0
117 store atomic i32 42, i32* @y monotonic, align 4
122 ; DSE across monotonic load (forbidden since the eliminated store is atomic)
123 define i32 @test11() {
124 ; CHECK-LABEL: test11
125 ; CHECK: store atomic i32 0
126 ; CHECK: store atomic i32 1
127 store atomic i32 0, i32* @x monotonic, align 4
128 %x = load atomic i32* @y monotonic, align 4
129 store atomic i32 1, i32* @x monotonic, align 4
133 ; DSE across monotonic store (forbidden since the eliminated store is atomic)
134 define void @test12() {
135 ; CHECK-LABEL: test12
136 ; CHECK: store atomic i32 0
137 ; CHECK: store atomic i32 1
138 store atomic i32 0, i32* @x monotonic, align 4
139 store atomic i32 42, i32* @y monotonic, align 4
140 store atomic i32 1, i32* @x monotonic, align 4
144 ; DSE is allowed across a pair of an atomic read and then write.
145 define i32 @test13() {
146 ; CHECK-LABEL: test13
147 ; CHECK-NOT: store i32 0
150 %x = load atomic i32* @y seq_cst, align 4
151 store atomic i32 %x, i32* @y seq_cst, align 4
156 ; Same if it is acquire-release instead of seq_cst/seq_cst
157 define i32 @test14() {
158 ; CHECK-LABEL: test14
159 ; CHECK-NOT: store i32 0
162 %x = load atomic i32* @y acquire, align 4
163 store atomic i32 %x, i32* @y release, align 4
168 ; But DSE is not allowed across a release-acquire pair.
169 define i32 @test15() {
170 ; CHECK-LABEL: test15
174 store atomic i32 0, i32* @y release, align 4
175 %x = load atomic i32* @y acquire, align 4