1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -gvn < %s | FileCheck %s
5 define i64 @test1(i1 %c, i64 %a, i64 %b) {
7 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
9 ; CHECK-NEXT: br label [[MERGE:%.*]]
11 ; CHECK-NEXT: br label [[MERGE]]
13 ; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A:%.*]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
14 ; CHECK-NEXT: ret i64 0
16 br i1 %c, label %taken, label %untaken
22 %phi1 = phi i64 [%a, %taken], [%b, %untaken]
23 %phi2 = phi i64 [%a, %taken], [%b, %untaken]
24 %ret = sub i64 %phi1, %phi2
28 declare void @llvm.assume(i1)
30 define i64 @test2(i1 %c, i64 %a, i64 %b) {
31 ; CHECK-LABEL: @test2(
32 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
34 ; CHECK-NEXT: [[ASSUMPTION:%.*]] = icmp eq i64 [[A:%.*]], 0
35 ; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUMPTION]])
36 ; CHECK-NEXT: br label [[MERGE:%.*]]
38 ; CHECK-NEXT: br label [[MERGE]]
40 ; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ 0, [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
41 ; CHECK-NEXT: ret i64 0
43 br i1 %c, label %taken, label %untaken
45 %assumption = icmp eq i64 %a, 0
46 call void @llvm.assume(i1 %assumption)
51 %phi1 = phi i64 [%a, %taken], [%b, %untaken]
52 %phi2 = phi i64 [0, %taken], [%b, %untaken]
53 %ret = sub i64 %phi1, %phi2
58 define i64 @test3(i1 %c, i64 %a, i64 %b) {
59 ; CHECK-LABEL: @test3(
60 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
62 ; CHECK-NEXT: [[ADD1:%.*]] = add i64 [[A:%.*]], 5
63 ; CHECK-NEXT: br label [[MERGE:%.*]]
65 ; CHECK-NEXT: br label [[MERGE]]
67 ; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[ADD1]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
68 ; CHECK-NEXT: ret i64 0
70 br i1 %c, label %taken, label %untaken
78 %phi1 = phi i64 [%add1, %taken], [%b, %untaken]
79 %phi2 = phi i64 [%add2, %taken], [%b, %untaken]
80 %ret = sub i64 %phi1, %phi2
84 define i64 @test4(i1 %c, i64 %a, i64 %b) {
85 ; CHECK-LABEL: @test4(
86 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
88 ; CHECK-NEXT: br label [[MERGE:%.*]]
90 ; CHECK-NEXT: br label [[MERGE]]
92 ; CHECK-NEXT: [[PHI1:%.*]] = phi i64 [ [[A:%.*]], [[TAKEN]] ], [ [[B:%.*]], [[UNTAKEN]] ]
93 ; CHECK-NEXT: br i1 [[C]], label [[TAKEN2:%.*]], label [[UNTAKEN2:%.*]]
95 ; CHECK-NEXT: [[ADD1:%.*]] = add i64 [[PHI1]], 5
96 ; CHECK-NEXT: br label [[MERGE2:%.*]]
98 ; CHECK-NEXT: br label [[MERGE2]]
100 ; CHECK-NEXT: [[PHI3:%.*]] = phi i64 [ [[ADD1]], [[TAKEN2]] ], [ [[PHI1]], [[UNTAKEN2]] ]
101 ; CHECK-NEXT: ret i64 0
103 br i1 %c, label %taken, label %untaken
109 %phi1 = phi i64 [%a, %taken], [%b, %untaken]
110 %phi2 = phi i64 [%a, %taken], [%b, %untaken]
111 br i1 %c, label %taken2, label %untaken2
113 %add1 = add i64 %phi1, 5
114 %add2 = add i64 %phi2, 5
119 %phi3 = phi i64 [%add1, %taken2], [%phi2, %untaken2]
120 %phi4 = phi i64 [%add2, %taken2], [%phi2, %untaken2]
121 %ret = sub i64 %phi4, %phi3
125 define i64 @test5(i1 %c, i64 %a) {
126 ; CHECK-LABEL: @test5(
127 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
129 ; CHECK-NEXT: [[ASSUMPTION:%.*]] = icmp eq i64 [[A:%.*]], 0
130 ; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUMPTION]])
131 ; CHECK-NEXT: br label [[MERGE:%.*]]
133 ; CHECK-NEXT: br label [[MERGE]]
135 ; CHECK-NEXT: ret i64 0
137 br i1 %c, label %taken, label %untaken
139 %assumption = icmp eq i64 %a, 0
140 call void @llvm.assume(i1 %assumption)
145 %phi = phi i64 [%a, %taken], [0, %untaken]
149 define i64 @test6(i1 %c, i64 %a) {
150 ; CHECK-LABEL: @test6(
151 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
153 ; CHECK-NEXT: [[ASSUMPTION:%.*]] = icmp eq i64 [[A:%.*]], 0
154 ; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUMPTION]])
155 ; CHECK-NEXT: br label [[MERGE:%.*]]
157 ; CHECK-NEXT: br label [[MERGE]]
159 ; CHECK-NEXT: ret i64 0
161 br i1 %c, label %taken, label %untaken
163 %assumption = icmp eq i64 %a, 0
164 call void @llvm.assume(i1 %assumption)
171 %phi = phi i64 [%a, %next], [0, %untaken]
175 ; negative test, phi use is NOT dominated by assume
176 define i64 @test7(i1 %c, i64 %a) {
177 ; CHECK-LABEL: @test7(
178 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
180 ; CHECK-NEXT: [[ASSUMPTION:%.*]] = icmp eq i64 [[A:%.*]], 0
181 ; CHECK-NEXT: call void @llvm.assume(i1 [[ASSUMPTION]])
182 ; CHECK-NEXT: br label [[MERGE:%.*]]
184 ; CHECK-NEXT: br label [[MERGE]]
186 ; CHECK-NEXT: ret i64 [[A]]
188 br i1 %c, label %taken, label %untaken
190 %assumption = icmp eq i64 %a, 0
191 call void @llvm.assume(i1 %assumption)
198 %phi = phi i64 [%a, %merge]