blob: 2e84298ad400a22fbe98e6fb4b594a55dd1550aa [file] [log] [blame]
Eli Friedman9a468152011-08-17 22:22:24 +00001; RUN: opt -basicaa -dse -S < %s | FileCheck %s
2
3target 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"
4target triple = "x86_64-apple-macosx10.7.0"
5
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 them.
9
10@x = common global i32 0, align 4
11@y = common global i32 0, align 4
12
13declare void @randomop(i32*)
14
15; DSE across unordered store (allowed)
16define void @test1() nounwind uwtable ssp {
17; CHECK: test1
18; CHECK-NOT: store i32 0
19; CHECK: store i32 1
20entry:
21 store i32 0, i32* @x
22 store atomic i32 0, i32* @y unordered, align 4
23 store i32 1, i32* @x
24 ret void
25}
26
27; DSE across seq_cst load (allowed in theory; not implemented ATM)
28define i32 @test2() nounwind uwtable ssp {
29; CHECK: test2
30; CHECK: store i32 0
31; CHECK: store i32 1
32entry:
33 store i32 0, i32* @x
34 %x = load atomic i32* @y seq_cst, align 4
35 store i32 1, i32* @x
36 ret i32 %x
37}
38
39; DSE across seq_cst store (store before atomic store must not be removed)
40define void @test3() nounwind uwtable ssp {
41; CHECK: test3
42; CHECK: store i32
43; CHECK: store atomic i32 2
44entry:
45 store i32 0, i32* @x
46 store atomic i32 2, i32* @y seq_cst, align 4
47 store i32 1, i32* @x
48 ret void
49}
50
51; DSE remove unordered store (allowed)
52define void @test4() nounwind uwtable ssp {
53; CHECK: test4
54; CHECK-NOT: store atomic
55; CHECK: store i32 1
56entry:
57 store atomic i32 0, i32* @x unordered, align 4
58 store i32 1, i32* @x
59 ret void
60}
61
62; DSE unordered store overwriting non-atomic store (allowed)
63define void @test5() nounwind uwtable ssp {
64; CHECK: test5
65; CHECK: store atomic i32 1
66entry:
67 store i32 0, i32* @x
68 store atomic i32 1, i32* @x unordered, align 4
69 ret void
70}
71
72; DSE no-op unordered atomic store (allowed)
73define void @test6() nounwind uwtable ssp {
74; CHECK: test6
75; CHECK-NOT: store
76; CHECK: ret void
77entry:
78 %x = load atomic i32* @x unordered, align 4
79 store atomic i32 %x, i32* @x unordered, align 4
80 ret void
81}
82
83; DSE seq_cst store (be conservative; DSE doesn't have infrastructure
84; to reason about atomic operations).
85define void @test7() nounwind uwtable ssp {
86; CHECK: test7
87; CHECK: store atomic
88entry:
89 %a = alloca i32
90 store atomic i32 0, i32* %a seq_cst, align 4
91 ret void
92}
93
94; DSE and seq_cst load (be conservative; DSE doesn't have infrastructure
95; to reason about atomic operations).
96define i32 @test8() nounwind uwtable ssp {
97; CHECK: test8
98; CHECK: store
99; CHECK: load atomic
100entry:
101 %a = alloca i32
102 call void @randomop(i32* %a)
103 store i32 0, i32* %a, align 4
104 %x = load atomic i32* @x seq_cst, align 4
105 ret i32 %x
106}
107