1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -newgvn -S %s | FileCheck %s
4 ; Test cases where initially a PHI-of-ops can be simplified to an existing
5 ; value, but later we need to revisit the decision because the leader of
6 ; one of the operands used for the simplification changed.
10 define void @pr36501(i1 %c) {
11 ; CHECK-LABEL: @pr36501(
13 ; CHECK-NEXT: br label [[BB1:%.*]]
15 ; CHECK-NEXT: [[PHI_1:%.*]] = phi i32 [ -2022207984, [[BB:%.*]] ], [ 0, [[BB7:%.*]] ]
16 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB3:%.*]], label [[BB2:%.*]]
18 ; CHECK-NEXT: br label [[BB3]]
20 ; CHECK-NEXT: [[PHI_2:%.*]] = phi i32 [ -1, [[BB2]] ], [ [[PHI_1]], [[BB1]] ]
21 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[PHI_2]], 0
22 ; CHECK-NEXT: br i1 [[TMP5]], label [[BB6:%.*]], label [[BB7]]
24 ; CHECK-NEXT: br label [[BB7]]
26 ; CHECK-NEXT: [[PHIOFOPS:%.*]] = phi i1 [ [[TMP5]], [[BB3]] ], [ true, [[BB6]] ]
27 ; CHECK-NEXT: [[PHI_3:%.*]] = phi i32 [ [[PHI_2]], [[BB3]] ], [ 0, [[BB6]] ]
28 ; CHECK-NEXT: call void @use(i1 [[PHIOFOPS]])
29 ; CHECK-NEXT: br label [[BB1]]
35 %phi.1 = phi i32 [ -2022207984, %bb ], [ 0, %bb7 ]
36 br i1 %c, label %bb3, label %bb2
42 %phi.2 = phi i32 [ -1, %bb2 ], [ %phi.1, %bb1 ]
43 %tmp5 = icmp eq i32 %phi.2, 0
44 br i1 %tmp5, label %bb6, label %bb7
49 bb7: ; preds = %bb6, %bb3
50 %phi.3 = phi i32 [ %phi.2, %bb3 ], [ 0, %bb6 ]
51 %tmp9 = icmp eq i32 %phi.3, 0
52 call void @use(i1 %tmp9)
56 define void @pr42422(i1 %c.1, i1 %c.2) {
57 ; CHECK-LABEL: @pr42422(
59 ; CHECK-NEXT: br label [[BB1:%.*]]
61 ; CHECK-NEXT: br label [[BB2:%.*]]
63 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ [[TMP23:%.*]], [[BB22:%.*]] ], [ 0, [[BB1]] ]
64 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sle i32 [[TMP]], 1
65 ; CHECK-NEXT: br i1 [[TMP3]], label [[BB4:%.*]], label [[BB24:%.*]]
67 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[BB5:%.*]], label [[BB6:%.*]]
69 ; CHECK-NEXT: br label [[BB19:%.*]]
71 ; CHECK-NEXT: br i1 [[C_2:%.*]], label [[BB7:%.*]], label [[BB8:%.*]]
73 ; CHECK-NEXT: br label [[BB16:%.*]]
75 ; CHECK-NEXT: [[TMP9:%.*]] = phi i64 [ [[TMP12:%.*]], [[BB11:%.*]] ], [ 0, [[BB6]] ]
76 ; CHECK-NEXT: [[TMP10:%.*]] = icmp sle i64 [[TMP9]], 1
77 ; CHECK-NEXT: br i1 [[TMP10]], label [[BB11]], label [[BB13:%.*]]
79 ; CHECK-NEXT: [[TMP12]] = add nsw i64 [[TMP9]], 1
80 ; CHECK-NEXT: br label [[BB8]]
82 ; CHECK-NEXT: br i1 true, label [[BB14:%.*]], label [[BB15:%.*]]
84 ; CHECK-NEXT: br label [[BB16]]
86 ; CHECK-NEXT: store i8 undef, i8* null, align 1
87 ; CHECK-NEXT: br label [[BB16]]
89 ; CHECK-NEXT: [[TMP17:%.*]] = phi i32 [ undef, [[BB15]] ], [ 1, [[BB14]] ], [ 9, [[BB7]] ]
90 ; CHECK-NEXT: switch i32 [[TMP17]], label [[BB19]] [
91 ; CHECK-NEXT: i32 0, label [[BB6]]
92 ; CHECK-NEXT: i32 9, label [[BB18:%.*]]
95 ; CHECK-NEXT: br label [[BB19]]
97 ; CHECK-NEXT: [[TMP20:%.*]] = phi i32 [ 0, [[BB18]] ], [ [[TMP17]], [[BB16]] ], [ 1, [[BB5]] ]
98 ; CHECK-NEXT: [[TMP21:%.*]] = icmp eq i32 [[TMP20]], 0
99 ; CHECK-NEXT: br i1 [[TMP21]], label [[BB22]], label [[BB25:%.*]]
101 ; CHECK-NEXT: [[TMP23]] = add nsw i32 [[TMP]], 1
102 ; CHECK-NEXT: br label [[BB2]]
104 ; CHECK-NEXT: br label [[BB25]]
106 ; CHECK-NEXT: [[PHIOFOPS:%.*]] = phi i1 [ true, [[BB24]] ], [ [[TMP21]], [[BB19]] ]
107 ; CHECK-NEXT: [[TMP26:%.*]] = phi i32 [ [[TMP20]], [[BB19]] ], [ 0, [[BB24]] ]
108 ; CHECK-NEXT: br i1 [[PHIOFOPS]], label [[BB1]], label [[BB28:%.*]]
110 ; CHECK-NEXT: ret void
115 bb1: ; preds = %bb25, %bb
118 bb2: ; preds = %bb22, %bb1
119 %tmp = phi i32 [ %tmp23, %bb22 ], [ 0, %bb1 ]
120 %tmp3 = icmp sle i32 %tmp, 1
121 br i1 %tmp3, label %bb4, label %bb24
124 br i1 %c.1, label %bb5, label %bb6
129 bb6: ; preds = %bb16, %bb4
130 br i1 %c.2, label %bb7, label %bb8
135 bb8: ; preds = %bb11, %bb6
136 %tmp9 = phi i64 [ %tmp12, %bb11 ], [ 0, %bb6 ]
137 %tmp10 = icmp sle i64 %tmp9, 1
138 br i1 %tmp10, label %bb11, label %bb13
141 %tmp12 = add nsw i64 %tmp9, 1
145 br i1 true, label %bb14, label %bb15
147 bb14: ; preds = %bb13
150 bb15: ; preds = %bb13
153 bb16: ; preds = %bb15, %bb14, %bb7
154 %tmp17 = phi i32 [ undef, %bb15 ], [ 1, %bb14 ], [ 9, %bb7 ]
155 switch i32 %tmp17, label %bb19 [
160 bb18: ; preds = %bb16
163 bb19: ; preds = %bb18, %bb16, %bb5
164 %tmp20 = phi i32 [ 0, %bb18 ], [ %tmp17, %bb16 ], [ 1, %bb5 ]
165 %tmp21 = icmp eq i32 %tmp20, 0
166 br i1 %tmp21, label %bb22, label %bb25
168 bb22: ; preds = %bb19
169 %tmp23 = add nsw i32 %tmp, 1
175 bb25: ; preds = %bb24, %bb19
176 %tmp26 = phi i32 [ %tmp20, %bb19 ], [ 0, %bb24 ]
177 %tmp27 = icmp eq i32 %tmp26, 0
178 br i1 %tmp27, label %bb1, label %bb28
180 bb28: ; preds = %bb25
184 define void @PR42557(i32 %tmp6, i1 %c.1, i1 %c.2) {
185 ; CHECK-LABEL: @PR42557(
187 ; CHECK-NEXT: br label [[BB1:%.*]]
189 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ 0, [[BB:%.*]] ], [ [[TMP6:%.*]], [[BB1]] ]
190 ; CHECK-NEXT: br i1 [[C_1:%.*]], label [[BB2:%.*]], label [[BB1]]
192 ; CHECK-NEXT: br i1 [[C_2:%.*]], label [[BB16:%.*]], label [[BB11:%.*]]
194 ; CHECK-NEXT: [[TMP17:%.*]] = add i32 [[TMP]], 1
195 ; CHECK-NEXT: br label [[BB11]]
197 ; CHECK-NEXT: [[TMP12:%.*]] = phi i32 [ [[TMP17]], [[BB16]] ], [ 0, [[BB2]] ]
198 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i32 [[TMP12]], 0
199 ; CHECK-NEXT: call void @use(i1 [[TMP13]])
200 ; CHECK-NEXT: [[TMP15:%.*]] = icmp ne i32 [[TMP]], 0
201 ; CHECK-NEXT: br i1 [[TMP15]], label [[BB18:%.*]], label [[BB19:%.*]]
203 ; CHECK-NEXT: br label [[BB19]]
205 ; CHECK-NEXT: [[PHIOFOPS:%.*]] = phi i1 [ [[TMP13]], [[BB11]] ], [ false, [[BB18]] ]
206 ; CHECK-NEXT: [[TMP20:%.*]] = phi i32 [ [[TMP12]], [[BB11]] ], [ 1, [[BB18]] ]
207 ; CHECK-NEXT: call void @use(i1 [[PHIOFOPS]])
208 ; CHECK-NEXT: ret void
213 bb1: ; preds = %bb1, %bb
214 %tmp = phi i32 [ 0, %bb ], [ %tmp6, %bb1 ]
215 br i1 %c.1, label %bb2, label %bb1
218 br i1 %c.2, label %bb16, label %bb11
221 %tmp17 = add i32 %tmp, 1
224 bb11: ; preds = %bb16, %bb2
225 %tmp12 = phi i32 [ %tmp17, %bb16 ], [ 0, %bb2 ]
226 %tmp13 = icmp eq i32 %tmp12, 0
227 call void @use(i1 %tmp13)
228 %tmp15 = icmp ne i32 %tmp, 0
229 br i1 %tmp15, label %bb18, label %bb19
231 bb18: ; preds = %bb11
234 bb19: ; preds = %bb18, %bb11
235 %tmp20 = phi i32 [ %tmp12, %bb11 ], [ 1, %bb18 ]
236 %tmp21 = icmp eq i32 %tmp20, 0
237 call void @use(i1 %tmp21)