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 remove unordered store (allowed)
27 define void @test4() {
29 ; CHECK-NOT: store atomic
31 store atomic i32 0, i32* @x unordered, align 4
36 ; DSE unordered store overwriting non-atomic store (allowed)
37 define void @test5() {
39 ; CHECK: store atomic i32 1
41 store atomic i32 1, i32* @x unordered, align 4
45 ; DSE no-op unordered atomic store (allowed)
46 define void @test6() {
50 %x = load atomic i32, i32* @x unordered, align 4
51 store atomic i32 %x, i32* @x unordered, align 4
55 ; DSE seq_cst store (be conservative; DSE doesn't have infrastructure
56 ; to reason about atomic operations).
57 define void @test7() {
61 store atomic i32 0, i32* %a seq_cst, align 4
65 ; DSE and seq_cst load (be conservative; DSE doesn't have infrastructure
66 ; to reason about atomic operations).
72 call void @randomop(i32* %a)
73 store i32 0, i32* %a, align 4
74 %x = load atomic i32, i32* @x seq_cst, align 4
78 ; DSE across monotonic load (allowed as long as the eliminated store isUnordered)
81 ; CHECK-NOT: store i32 0
84 %x = load atomic i32, i32* @y monotonic, align 4
89 ; DSE across monotonic store (allowed as long as the eliminated store isUnordered)
90 define void @test10() {
92 ; CHECK-NOT: store i32 0
95 store atomic i32 42, i32* @y monotonic, align 4
100 ; DSE across monotonic load (forbidden since the eliminated store is atomic)
101 define i32 @test11() {
102 ; CHECK-LABEL: test11
103 ; CHECK: store atomic i32 0
104 ; CHECK: store atomic i32 1
105 store atomic i32 0, i32* @x monotonic, align 4
106 %x = load atomic i32, i32* @y monotonic, align 4
107 store atomic i32 1, i32* @x monotonic, align 4
111 ; DSE across monotonic store (forbidden since the eliminated store is atomic)
112 define void @test12() {
113 ; CHECK-LABEL: test12
114 ; CHECK: store atomic i32 0
115 ; CHECK: store atomic i32 1
116 store atomic i32 0, i32* @x monotonic, align 4
117 store atomic i32 42, i32* @y monotonic, align 4
118 store atomic i32 1, i32* @x monotonic, align 4
122 ; But DSE is not allowed across a release-acquire pair.
123 define i32 @test15() {
124 ; CHECK-LABEL: test15
128 store atomic i32 0, i32* @y release, align 4
129 %x = load atomic i32, i32* @y acquire, align 4