1 ; RUN: opt -basicaa -gvn -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 @x = common global i32 0, align 4
7 @y = common global i32 0, align 4
9 ; GVN across unordered store (allowed)
10 define i32 @test1() nounwind uwtable ssp {
12 ; CHECK: add i32 %x, %x
14 %x = load i32, i32* @y
15 store atomic i32 %x, i32* @x unordered, align 4
16 %y = load i32, i32* @y
21 ; GVN across unordered load (allowed)
22 define i32 @test3() nounwind uwtable ssp {
24 ; CHECK: add i32 %x, %x
26 %x = load i32, i32* @y
27 %y = load atomic i32, i32* @x unordered, align 4
28 %z = load i32, i32* @y
34 ; GVN load to unordered load (allowed)
35 define i32 @test5() nounwind uwtable ssp {
37 ; CHECK: add i32 %x, %x
39 %x = load atomic i32, i32* @x unordered, align 4
40 %y = load i32, i32* @x
45 ; GVN unordered load to load (unordered load must not be removed)
46 define i32 @test6() nounwind uwtable ssp {
48 ; CHECK: load atomic i32, i32* @x unordered
50 %x = load i32, i32* @x
51 %x2 = load atomic i32, i32* @x unordered, align 4
56 ; GVN across release-acquire pair (forbidden)
57 define i32 @test7() nounwind uwtable ssp {
59 ; CHECK: add i32 %x, %y
61 %x = load i32, i32* @y
62 store atomic i32 %x, i32* @x release, align 4
63 %w = load atomic i32, i32* @x acquire, align 4
64 %y = load i32, i32* @y
69 ; GVN across monotonic store (allowed)
70 define i32 @test9() nounwind uwtable ssp {
72 ; CHECK: add i32 %x, %x
74 %x = load i32, i32* @y
75 store atomic i32 %x, i32* @x monotonic, align 4
76 %y = load i32, i32* @y
81 ; GVN of an unordered across monotonic load (not allowed)
82 define i32 @test10() nounwind uwtable ssp {
84 ; CHECK: add i32 %x, %y
86 %x = load atomic i32, i32* @y unordered, align 4
87 %clobber = load atomic i32, i32* @x monotonic, align 4
88 %y = load atomic i32, i32* @y monotonic, align 4
93 define i32 @PR22708(i1 %flag) {
94 ; CHECK-LABEL: PR22708
96 br i1 %flag, label %if.then, label %if.end
99 store i32 43, i32* @y, align 4
100 ; CHECK: store i32 43, i32* @y, align 4
104 load atomic i32, i32* @x acquire, align 4
105 %load = load i32, i32* @y, align 4
106 ; CHECK: load atomic i32, i32* @x acquire, align 4
107 ; CHECK: load i32, i32* @y, align 4