8c13d209c53a1bc6231b5e5bc36199db49dd623a
[oota-llvm.git] / test / Transforms / GVN / atomic.ll
1 ; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
2
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"
5
6 @x = common global i32 0, align 4
7 @y = common global i32 0, align 4
8
9 ; GVN across unordered store (allowed)
10 define i32 @test1() nounwind uwtable ssp {
11 ; CHECK-LABEL: test1
12 ; CHECK: add i32 %x, %x
13 entry:
14   %x = load i32* @y
15   store atomic i32 %x, i32* @x unordered, align 4
16   %y = load i32* @y
17   %z = add i32 %x, %y
18   ret i32 %z
19 }
20
21 ; GVN across seq_cst store (allowed)
22 define i32 @test2() nounwind uwtable ssp {
23 ; CHECK-LABEL: test2
24 ; CHECK: add i32 %x, %x
25 entry:
26   %x = load i32* @y
27   store atomic i32 %x, i32* @x seq_cst, align 4
28   %y = load i32* @y
29   %z = add i32 %x, %y
30   ret i32 %z
31 }
32
33 ; GVN across unordered load (allowed)
34 define i32 @test3() nounwind uwtable ssp {
35 ; CHECK-LABEL: test3
36 ; CHECK: add i32 %x, %x
37 entry:
38   %x = load i32* @y
39   %y = load atomic i32* @x unordered, align 4
40   %z = load i32* @y
41   %a = add i32 %x, %z
42   %b = add i32 %y, %a
43   ret i32 %b
44 }
45
46 ; GVN across acquire load (allowed as the original load was not atomic)
47 define i32 @test4() nounwind uwtable ssp {
48 ; CHECK-LABEL: test4
49 ; CHECK: load atomic i32* @x
50 ; CHECK-NOT: load i32* @y
51 entry:
52   %x = load i32* @y
53   %y = load atomic i32* @x seq_cst, align 4
54   %x2 = load i32* @y
55   %x3 = add i32 %x, %x2
56   %y2 = add i32 %y, %x3
57   ret i32 %y2
58 }
59
60 ; GVN load to unordered load (allowed)
61 define i32 @test5() nounwind uwtable ssp {
62 ; CHECK-LABEL: test5
63 ; CHECK: add i32 %x, %x
64 entry:
65   %x = load atomic i32* @x unordered, align 4
66   %y = load i32* @x
67   %z = add i32 %x, %y
68   ret i32 %z
69 }
70
71 ; GVN unordered load to load (unordered load must not be removed)
72 define i32 @test6() nounwind uwtable ssp {
73 ; CHECK-LABEL: test6
74 ; CHECK: load atomic i32* @x unordered
75 entry:
76   %x = load i32* @x
77   %x2 = load atomic i32* @x unordered, align 4
78   %x3 = add i32 %x, %x2
79   ret i32 %x3
80 }
81
82 ; GVN across release-acquire pair (forbidden)
83 define i32 @test7() nounwind uwtable ssp {
84 ; CHECK-LABEL: test7
85 ; CHECK: add i32 %x, %y
86 entry:
87   %x = load i32* @y
88   store atomic i32 %x, i32* @x release, align 4
89   %w = load atomic i32* @x acquire, align 4
90   %y = load i32* @y
91   %z = add i32 %x, %y
92   ret i32 %z
93 }
94
95 ; GVN across acquire-release pair (allowed)
96 define i32 @test8() nounwind uwtable ssp {
97 ; CHECK-LABEL: test8
98 ; CHECK: add i32 %x, %x
99 entry:
100   %x = load i32* @y
101   %w = load atomic i32* @x acquire, align 4
102   store atomic i32 %x, i32* @x release, align 4
103   %y = load i32* @y
104   %z = add i32 %x, %y
105   ret i32 %z
106 }
107
108 ; GVN across monotonic store (allowed)
109 define i32 @test9() nounwind uwtable ssp {
110 ; CHECK-LABEL: test9
111 ; CHECK: add i32 %x, %x
112 entry:
113   %x = load i32* @y
114   store atomic i32 %x, i32* @x monotonic, align 4
115   %y = load i32* @y
116   %z = add i32 %x, %y
117   ret i32 %z
118 }
119
120 ; GVN of an unordered across monotonic load (not allowed)
121 define i32 @test10() nounwind uwtable ssp {
122 ; CHECK-LABEL: test10
123 ; CHECK: add i32 %x, %y
124 entry:
125   %x = load atomic i32* @y unordered, align 4
126   %clobber = load atomic i32* @x monotonic, align 4
127   %y = load atomic i32* @y monotonic, align 4
128   %z = add i32 %x, %y
129   ret i32 %z
130 }
131