1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -fix-irreducible --verify-loop-info -S | FileCheck %s
3 ; RUN: opt < %s -passes='fix-irreducible,verify<loops>' -S | FileCheck %s
4 ; RUN: opt < %s -passes='verify<loops>,fix-irreducible,verify<loops>' -S | FileCheck %s
6 define i32 @basic(i1 %PredEntry, i1 %PredLeft, i1 %PredRight, i32 %X, i32 %Y) {
9 ; CHECK-NEXT: [[PREDENTRY_INV:%.*]] = xor i1 [[PREDENTRY:%.*]], true
10 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
12 ; CHECK-NEXT: [[L_PHI:%.*]] = phi i32 [ [[R_PHI_MOVED:%.*]], [[RIGHT:%.*]] ], [ [[L_PHI_MOVED:%.*]], [[IRR_GUARD]] ]
13 ; CHECK-NEXT: [[L:%.*]] = add i32 [[L_PHI]], 1
14 ; CHECK-NEXT: br i1 [[PREDLEFT:%.*]], label [[IRR_GUARD]], label [[EXIT:%.*]]
16 ; CHECK-NEXT: br i1 [[PREDRIGHT:%.*]], label [[LEFT:%.*]], label [[EXIT]]
18 ; CHECK-NEXT: [[Z:%.*]] = phi i32 [ [[L]], [[LEFT]] ], [ [[R_PHI_MOVED]], [[RIGHT]] ]
19 ; CHECK-NEXT: ret i32 [[Z]]
21 ; CHECK-NEXT: [[L_PHI_MOVED]] = phi i32 [ [[L_PHI_MOVED]], [[LEFT]] ], [ [[X:%.*]], [[ENTRY:%.*]] ]
22 ; CHECK-NEXT: [[R_PHI_MOVED]] = phi i32 [ [[L]], [[LEFT]] ], [ [[Y:%.*]], [[ENTRY]] ]
23 ; CHECK-NEXT: [[GUARD_RIGHT:%.*]] = phi i1 [ true, [[LEFT]] ], [ [[PREDENTRY_INV]], [[ENTRY]] ]
24 ; CHECK-NEXT: br i1 [[GUARD_RIGHT]], label [[RIGHT]], label [[LEFT]]
27 br i1 %PredEntry, label %left, label %right
30 %L.phi = phi i32 [%X, %entry], [%R.phi, %right]
31 %L = add i32 %L.phi, 1
32 br i1 %PredLeft, label %right, label %exit
35 %R.phi = phi i32 [%Y, %entry], [%L, %left]
36 br i1 %PredRight, label %left, label %exit
39 %Z = phi i32 [%L, %left], [%R.phi, %right]
43 define i32 @feedback_loop(i1 %PredEntry, i1 %PredLeft, i1 %PredRight, i32 %X, i32 %Y) {
44 ; CHECK-LABEL: @feedback_loop(
46 ; CHECK-NEXT: [[PREDENTRY_INV:%.*]] = xor i1 [[PREDENTRY:%.*]], true
47 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
49 ; CHECK-NEXT: [[L_PHI:%.*]] = phi i32 [ [[R_PHI_MOVED:%.*]], [[RIGHT:%.*]] ], [ [[L_PHI_MOVED:%.*]], [[IRR_GUARD]] ]
50 ; CHECK-NEXT: br i1 [[PREDLEFT:%.*]], label [[IRR_GUARD]], label [[EXIT:%.*]]
52 ; CHECK-NEXT: br i1 [[PREDRIGHT:%.*]], label [[LEFT:%.*]], label [[EXIT]]
54 ; CHECK-NEXT: [[Z:%.*]] = phi i32 [ [[L_PHI]], [[LEFT]] ], [ [[R_PHI_MOVED]], [[RIGHT]] ]
55 ; CHECK-NEXT: ret i32 [[Z]]
57 ; CHECK-NEXT: [[L_PHI_MOVED]] = phi i32 [ [[L_PHI_MOVED]], [[LEFT]] ], [ [[X:%.*]], [[ENTRY:%.*]] ]
58 ; CHECK-NEXT: [[R_PHI_MOVED]] = phi i32 [ [[L_PHI]], [[LEFT]] ], [ [[Y:%.*]], [[ENTRY]] ]
59 ; CHECK-NEXT: [[GUARD_RIGHT:%.*]] = phi i1 [ true, [[LEFT]] ], [ [[PREDENTRY_INV]], [[ENTRY]] ]
60 ; CHECK-NEXT: br i1 [[GUARD_RIGHT]], label [[RIGHT]], label [[LEFT]]
63 br i1 %PredEntry, label %left, label %right
66 %L.phi = phi i32 [%X, %entry], [%R.phi, %right]
67 br i1 %PredLeft, label %right, label %exit
70 %R.phi = phi i32 [%Y, %entry], [%L.phi, %left]
71 br i1 %PredRight, label %left, label %exit
74 %Z = phi i32 [%L.phi, %left], [%R.phi, %right]
78 define i32 @multiple_predecessors(i1 %PredEntry, i1 %PredA, i1 %PredB, i1 %PredC, i1 %PredD, i32 %X, i32 %Y) {
79 ; CHECK-LABEL: @multiple_predecessors(
81 ; CHECK-NEXT: [[PREDB_INV:%.*]] = xor i1 [[PREDB:%.*]], true
82 ; CHECK-NEXT: br i1 [[PREDENTRY:%.*]], label [[A:%.*]], label [[B:%.*]]
84 ; CHECK-NEXT: [[A_INC:%.*]] = add i32 [[X:%.*]], 1
85 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
87 ; CHECK-NEXT: br label [[IRR_GUARD]]
89 ; CHECK-NEXT: br i1 [[PREDC:%.*]], label [[D:%.*]], label [[EXIT:%.*]]
91 ; CHECK-NEXT: [[D_PHI:%.*]] = phi i32 [ [[C_PHI_MOVED:%.*]], [[C:%.*]] ], [ [[D_PHI_MOVED:%.*]], [[IRR_GUARD]] ]
92 ; CHECK-NEXT: [[D_INC:%.*]] = add i32 [[D_PHI]], 1
93 ; CHECK-NEXT: br i1 [[PREDD:%.*]], label [[EXIT]], label [[IRR_GUARD]]
95 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[C_PHI_MOVED]], [[C]] ], [ [[D_INC]], [[D]] ]
96 ; CHECK-NEXT: ret i32 [[RET]]
98 ; CHECK-NEXT: [[D_PHI_MOVED]] = phi i32 [ [[D_PHI_MOVED]], [[D]] ], [ [[Y:%.*]], [[B]] ], [ [[A_INC]], [[A]] ]
99 ; CHECK-NEXT: [[C_PHI_MOVED]] = phi i32 [ [[D_INC]], [[D]] ], [ [[Y]], [[B]] ], [ [[X]], [[A]] ]
100 ; CHECK-NEXT: [[GUARD_C:%.*]] = phi i1 [ true, [[D]] ], [ [[PREDB_INV]], [[B]] ], [ [[PREDA:%.*]], [[A]] ]
101 ; CHECK-NEXT: br i1 [[GUARD_C]], label [[C]], label [[D]]
104 br i1 %PredEntry, label %A, label %B
107 %A.inc = add i32 %X, 1
108 br i1 %PredA, label %C, label %D
111 br i1 %PredB, label %D, label %C
114 %C.phi = phi i32 [%X, %A], [%Y, %B], [%D.inc, %D]
115 br i1 %PredC, label %D, label %exit
118 %D.phi = phi i32 [%A.inc, %A], [%Y, %B], [%C.phi, %C]
119 %D.inc = add i32 %D.phi, 1
120 br i1 %PredD, label %exit, label %C
123 %ret = phi i32 [%C.phi, %C], [%D.inc, %D]
127 define i32 @separate_predecessors(i1 %PredEntry, i1 %PredA, i1 %PredB, i1 %PredC, i1 %PredD, i32 %X, i32 %Y) {
128 ; CHECK-LABEL: @separate_predecessors(
130 ; CHECK-NEXT: br i1 [[PREDENTRY:%.*]], label [[A:%.*]], label [[B:%.*]]
132 ; CHECK-NEXT: [[A_INC:%.*]] = add i32 [[X:%.*]], 1
133 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
135 ; CHECK-NEXT: br label [[IRR_GUARD]]
137 ; CHECK-NEXT: [[C_PHI:%.*]] = phi i32 [ [[D_INC:%.*]], [[D:%.*]] ], [ [[C_PHI_MOVED:%.*]], [[IRR_GUARD]] ]
138 ; CHECK-NEXT: br i1 [[PREDC:%.*]], label [[EXIT:%.*]], label [[IRR_GUARD]]
140 ; CHECK-NEXT: [[D_INC]] = add i32 [[D_PHI_MOVED:%.*]], 1
141 ; CHECK-NEXT: br i1 [[PREDD:%.*]], label [[EXIT]], label [[C:%.*]]
143 ; CHECK-NEXT: [[RET:%.*]] = phi i32 [ [[C_PHI]], [[C]] ], [ [[D_INC]], [[D]] ]
144 ; CHECK-NEXT: ret i32 [[RET]]
146 ; CHECK-NEXT: [[C_PHI_MOVED]] = phi i32 [ [[C_PHI_MOVED]], [[C]] ], [ poison, [[B]] ], [ [[X]], [[A]] ]
147 ; CHECK-NEXT: [[D_PHI_MOVED]] = phi i32 [ [[C_PHI]], [[C]] ], [ [[Y:%.*]], [[B]] ], [ poison, [[A]] ]
148 ; CHECK-NEXT: [[GUARD_D:%.*]] = phi i1 [ true, [[C]] ], [ true, [[B]] ], [ false, [[A]] ]
149 ; CHECK-NEXT: br i1 [[GUARD_D]], label [[D]], label [[C]]
152 br i1 %PredEntry, label %A, label %B
155 %A.inc = add i32 %X, 1
162 %C.phi = phi i32 [%X, %A], [%D.inc, %D]
163 br i1 %PredC, label %exit, label %D
166 %D.phi = phi i32 [%Y, %B], [%C.phi, %C]
167 %D.inc = add i32 %D.phi, 1
168 br i1 %PredD, label %exit, label %C
171 %ret = phi i32 [%C.phi, %C], [%D.inc, %D]
175 define void @four_headers(i1 %PredEntry, i1 %PredX, i1 %PredY, i1 %PredD) {
176 ; CHECK-LABEL: @four_headers(
178 ; CHECK-NEXT: [[PREDY_INV:%.*]] = xor i1 [[PREDY:%.*]], true
179 ; CHECK-NEXT: br i1 [[PREDENTRY:%.*]], label [[X:%.*]], label [[Y:%.*]]
181 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
183 ; CHECK-NEXT: br label [[IRR_GUARD]]
185 ; CHECK-NEXT: br label [[B:%.*]]
187 ; CHECK-NEXT: br label [[C:%.*]]
189 ; CHECK-NEXT: br label [[IRR_GUARD]]
191 ; CHECK-NEXT: br i1 [[PREDD:%.*]], label [[EXIT:%.*]], label [[A:%.*]]
193 ; CHECK-NEXT: ret void
195 ; CHECK-NEXT: [[GUARD_D:%.*]] = phi i1 [ true, [[C]] ], [ [[PREDY_INV]], [[Y]] ], [ false, [[X]] ]
196 ; CHECK-NEXT: [[GUARD_C:%.*]] = phi i1 [ false, [[C]] ], [ true, [[Y]] ], [ false, [[X]] ]
197 ; CHECK-NEXT: [[GUARD_A:%.*]] = phi i1 [ false, [[C]] ], [ false, [[Y]] ], [ [[PREDX:%.*]], [[X]] ]
198 ; CHECK-NEXT: br i1 [[GUARD_D]], label [[D:%.*]], label [[IRR_GUARD1:%.*]]
200 ; CHECK-NEXT: br i1 [[GUARD_C]], label [[C]], label [[IRR_GUARD2:%.*]]
202 ; CHECK-NEXT: br i1 [[GUARD_A]], label [[A]], label [[B]]
205 br i1 %PredEntry, label %X, label %Y
208 br i1 %PredX, label %A, label %B
211 br i1 %PredY, label %C, label %D
223 br i1 %PredD, label %exit, label %A
229 define i32 @hidden_nodes(i1 %PredEntry, i1 %PredA, i1 %PredB, i1 %PredC, i1 %PredD, i32 %X, i32 %Y) {
230 ; CHECK-LABEL: @hidden_nodes(
232 ; CHECK-NEXT: [[PREDENTRY_INV:%.*]] = xor i1 [[PREDENTRY:%.*]], true
233 ; CHECK-NEXT: br label [[IRR_GUARD:%.*]]
235 ; CHECK-NEXT: [[A_PHI:%.*]] = phi i32 [ [[C_INC:%.*]], [[E:%.*]] ], [ [[A_PHI_MOVED:%.*]], [[IRR_GUARD]] ]
236 ; CHECK-NEXT: [[A_INC:%.*]] = add i32 [[A_PHI]], 1
237 ; CHECK-NEXT: br label [[IRR_GUARD]]
239 ; CHECK-NEXT: br label [[C:%.*]]
241 ; CHECK-NEXT: [[C_INC]] = add i32 [[B_PHI_MOVED:%.*]], 1
242 ; CHECK-NEXT: br label [[D:%.*]]
244 ; CHECK-NEXT: br i1 [[PREDD:%.*]], label [[EXIT:%.*]], label [[E]]
246 ; CHECK-NEXT: br label [[A:%.*]]
248 ; CHECK-NEXT: ret i32 [[B_PHI_MOVED]]
250 ; CHECK-NEXT: [[A_PHI_MOVED]] = phi i32 [ [[A_PHI_MOVED]], [[A]] ], [ [[X:%.*]], [[ENTRY:%.*]] ]
251 ; CHECK-NEXT: [[B_PHI_MOVED]] = phi i32 [ [[A_INC]], [[A]] ], [ [[Y:%.*]], [[ENTRY]] ]
252 ; CHECK-NEXT: [[GUARD_B:%.*]] = phi i1 [ true, [[A]] ], [ [[PREDENTRY_INV]], [[ENTRY]] ]
253 ; CHECK-NEXT: br i1 [[GUARD_B]], label [[B:%.*]], label [[A]]
256 br i1 %PredEntry, label %A, label %B
259 %A.phi = phi i32 [%X, %entry], [%C.inc, %E]
260 %A.inc = add i32 %A.phi, 1
264 %B.phi = phi i32 [%A.inc, %A], [%Y, %entry]
268 %C.inc = add i32 %B.phi, 1
272 br i1 %PredD, label %exit, label %E