1; RUN: opt -S -gvn-hoist < %s | FileCheck %s
2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3target triple = "x86_64-unknown-linux-gnu"
4
5define void @test1(i1 %b, i32* %x) {
6entry:
7  br i1 %b, label %if.then, label %if.else
8
9if.then:                                          ; preds = %entry
10  store i32 2, i32* %x, align 4, !tbaa !1
11  br label %if.end
12
13if.else:                                          ; preds = %entry
14  store i32 2, i32* %x, align 4, !tbaa !5
15  br label %if.end
16
17if.end:                                           ; preds = %if.else, %if.then
18  ret void
19}
20; CHECK-LABEL: define void @test1(
21; CHECK: store i32 2, i32* %x, align 4
22; CHECK-NEXT: br i1 %b
23
24define void @test2(i1 %b, i32* %x) {
25entry:
26  br i1 %b, label %if.then, label %if.else
27
28if.then:                                          ; preds = %entry
29  %gep1 = getelementptr inbounds i32, i32* %x, i64 1
30  store i32 2, i32* %gep1, align 4, !tbaa !1
31  br label %if.end
32
33if.else:                                          ; preds = %entry
34  %gep2 = getelementptr inbounds i32, i32* %x, i64 1
35  store i32 2, i32* %gep2, align 4, !tbaa !5
36  br label %if.end
37
38if.end:                                           ; preds = %if.else, %if.then
39  ret void
40}
41; CHECK-LABEL: define void @test2(
42; CHECK: %[[gep:.*]] = getelementptr inbounds i32, i32* %x, i64 1
43; CHECK: store i32 2, i32* %[[gep]], align 4
44; CHECK-NEXT: br i1 %b
45
46define void @test3(i1 %b, i32* %x) {
47entry:
48  br i1 %b, label %if.then, label %if.else
49
50if.then:                                          ; preds = %entry
51  %gep1 = getelementptr inbounds i32, i32* %x, i64 1
52  store i32 2, i32* %gep1, align 4, !tbaa !1
53  br label %if.end
54
55if.else:                                          ; preds = %entry
56  %gep2 = getelementptr i32, i32* %x, i64 1
57  store i32 2, i32* %gep2, align 4, !tbaa !5
58  br label %if.end
59
60if.end:                                           ; preds = %if.else, %if.then
61  ret void
62}
63; CHECK-LABEL: define void @test3(
64; CHECK: %[[gep:.*]] = getelementptr i32, i32* %x, i64 1
65; CHECK: store i32 2, i32* %[[gep]], align 4
66; CHECK-NEXT: br i1 %b
67
68!1 = !{!2, !2, i64 0}
69!2 = !{!"int", !3, i64 0}
70!3 = !{!"omnipotent char", !4, i64 0}
71!4 = !{!"Simple C++ TBAA"}
72!5 = !{!6, !6, i64 0}
73!6 = !{!"_ZTS1e", !3, i64 0}
74
75define i32 @test4(i1 %b, i32* %y) {
76entry:
77  br i1 %b, label %if.then, label %if.end
78
79if.then:                                          ; preds = %entry
80  %0 = load i32, i32* %y, align 4, !range !7
81  br label %return
82
83if.end:                                           ; preds = %entry
84  %1 = load i32, i32* %y, align 4, !range !8
85  br label %return
86
87return:                                           ; preds = %if.end, %if.then
88  %retval.0 = phi i32 [ %0, %if.then ], [ %1, %if.end ]
89  ret i32 %retval.0
90}
91; CHECK-LABEL: define i32 @test4(
92; CHECK: %[[load:.*]] = load i32, i32* %y, align 4, !range ![[range_md:.*]]
93; CHECK: %[[phi:.*]] = phi i32 [ %[[load]], %{{.*}} ], [ %[[load]], %{{.*}} ]
94; CHECK: ret i32 %[[phi]]
95
96define i32* @test5(i1 %b, i32** %y) {
97entry:
98  br i1 %b, label %if.then, label %if.end
99
100if.then:                                          ; preds = %entry
101  %0 = load i32*, i32** %y, align 4, !nonnull !9
102  br label %return
103
104if.end:                                           ; preds = %entry
105  %1 = load i32*, i32** %y, align 4
106  br label %return
107
108return:                                           ; preds = %if.end, %if.then
109  %retval.0 = phi i32* [ %0, %if.then ], [ %1, %if.end ]
110  ret i32* %retval.0
111}
112; CHECK-LABEL: define i32* @test5(
113; CHECK: %[[load:.*]] = load i32*, i32** %y, align 4
114; CHECK-NOT: !nonnull
115; CHECK: %[[phi:.*]] = phi i32* [ %[[load]], %{{.*}} ], [ %[[load]], %{{.*}} ]
116; CHECK: ret i32* %[[phi]]
117
118!7 = !{i32 0, i32 2}
119!8 = !{i32 3, i32 4}
120!9 = !{}
121; CHECK: ![[range_md]] = !{i32 0, i32 2, i32 3, i32 4}
122