1 ; RUN: opt < %s -S -loop-unroll -verify-loop-info -unroll-scev | FileCheck %s
3 ; Unit tests for LoopInfo::updateUnloop.
5 declare i1 @check() nounwind
7 ; Ensure that tail->inner is removed and rely on verify-loopinfo to
10 ; CHECK: @skiplevelexit
14 define void @skiplevelexit() nounwind {
22 %iv = phi i32 [ 0, %outer ], [ %inc, %tail ]
24 %wbucond = call zeroext i1 @check()
25 br i1 %wbucond, label %outer.backedge, label %tail
28 br i1 false, label %inner, label %exit
37 ; Remove the middle loop of a triply nested loop tree.
38 ; Ensure that only the middle loop is removed and rely on verify-loopinfo to
41 ; CHECK: @unloopNested
44 ; CHECK: br i1 %cmp3, label %if.then, label %if.end
46 ; CHECK: while.end14.i:
47 ; CHECK: br i1 %call15.i, label %if.end.i, label %exit
48 ; Middle loop control should no longer reach %while.cond.
49 ; Now it is the outer loop backedge.
51 ; CHECK: br label %while.cond.outer
52 define void @unloopNested() {
54 br label %while.cond.outer
60 %cmp = call zeroext i1 @check()
61 br i1 %cmp, label %while.body, label %while.end
64 %cmp3 = call zeroext i1 @check()
65 br i1 %cmp3, label %if.then, label %if.end
71 %cmp.i48 = call zeroext i1 @check()
72 br i1 %cmp.i48, label %if.then.i, label %if.else20.i
75 %cmp8.i = call zeroext i1 @check()
76 br i1 %cmp8.i, label %merge, label %if.else.i
82 %cmp25.i = call zeroext i1 @check()
83 br i1 %cmp25.i, label %merge, label %if.else28.i
89 br label %while.cond2.i
92 %cmp.i = call zeroext i1 @check()
93 br i1 %cmp.i, label %while.cond2.backedge.i, label %while.end.i
95 while.cond2.backedge.i:
96 br label %while.cond2.i
99 %cmp1114.i = call zeroext i1 @check()
100 br i1 %cmp1114.i, label %while.body12.lr.ph.i, label %while.end14.i
102 while.body12.lr.ph.i:
103 br label %while.end14.i
106 %call15.i = call zeroext i1 @check()
107 br i1 %call15.i, label %if.end.i, label %exit
110 br label %while.cond2.backedge.i
113 br i1 false, label %while.cond, label %if.else
116 br label %while.cond.outer
125 ; Remove the middle loop of a deeply nested loop tree.
126 ; Ensure that only the middle loop is removed and rely on verify-loopinfo to
129 ; CHECK: @unloopDeepNested
130 ; Inner-inner loop control.
131 ; CHECK: while.cond.us.i:
132 ; CHECK: br i1 %cmp.us.i, label %next_data.exit, label %while.body.us.i
133 ; CHECK: if.then.us.i:
134 ; CHECK: br label %while.cond.us.i
137 ; CHECK: br label %while.cond.outer.i
138 ; Middle loop control (removed).
139 ; CHECK: valid_data.exit:
141 ; CHECK: %cmp = call zeroext i1 @check()
142 ; Outer loop control.
143 ; CHECK: copy_data.exit:
144 ; CHECK: br i1 %cmp38, label %if.then39, label %while.cond.outer
145 ; Outer-outer loop tail.
146 ; CHECK: while.cond.outer.outer.backedge:
147 ; CHECK: br label %while.cond.outer.outer
148 define void @unloopDeepNested() nounwind {
149 for.cond8.preheader.i:
150 %cmp113.i = call zeroext i1 @check()
151 br i1 %cmp113.i, label %make_data.exit, label %for.body13.lr.ph.i
154 br label %make_data.exit
157 br label %while.cond.outer.outer
159 while.cond.outer.outer:
160 br label %while.cond.outer
166 br label %while.cond.outer.i
169 %tmp192.ph.i = call zeroext i1 @check()
170 br i1 %tmp192.ph.i, label %while.cond.outer.split.us.i, label %while.body.loopexit
172 while.cond.outer.split.us.i:
173 br label %while.cond.us.i
176 %cmp.us.i = call zeroext i1 @check()
177 br i1 %cmp.us.i, label %next_data.exit, label %while.body.us.i
180 %cmp7.us.i = call zeroext i1 @check()
181 br i1 %cmp7.us.i, label %if.then.us.i, label %if.else.i
184 br label %while.cond.us.i
187 br label %while.cond.outer.i
190 %tmp192.ph.i.lcssa28 = call zeroext i1 @check()
191 br i1 %tmp192.ph.i.lcssa28, label %while.end, label %while.body
197 br label %while.cond.i
200 %cmp.i = call zeroext i1 @check()
201 br i1 %cmp.i, label %valid_data.exit, label %while.body.i
204 %cmp7.i = call zeroext i1 @check()
205 br i1 %cmp7.i, label %valid_data.exit, label %if.end.i
208 br label %while.cond.i
211 br i1 true, label %if.then, label %while.cond
214 %cmp = call zeroext i1 @check()
215 br i1 %cmp, label %if.then12, label %if.end
221 %tobool3.i = call zeroext i1 @check()
222 br i1 %tobool3.i, label %copy_data.exit, label %while.body.lr.ph.i
225 br label %copy_data.exit
228 %cmp38 = call zeroext i1 @check()
229 br i1 %cmp38, label %if.then39, label %while.cond.outer
232 %cmp5.i = call zeroext i1 @check()
233 br i1 %cmp5.i, label %while.cond.outer.outer.backedge, label %for.cond8.preheader.i8.thread
235 for.cond8.preheader.i8.thread:
236 br label %while.cond.outer.outer.backedge
238 while.cond.outer.outer.backedge:
239 br label %while.cond.outer.outer
245 ; Remove a nested loop with irreducible control flow.
246 ; Ensure that only the middle loop is removed and rely on verify-loopinfo to
249 ; CHECK: @unloopIrreducible
252 ; CHECK: br label %for.cond103t
253 ; Nested loop (removed).
255 ; CHECK: br label %for.inc163
256 define void @unloopIrreducible() nounwind {
262 %cmp2113 = call zeroext i1 @check()
263 br i1 %cmp2113, label %for.body22.lr.ph, label %for.inc163
275 %cmp424 = call zeroext i1 @check()
276 br i1 %cmp424, label %for.body43.lr.ph, label %for.end93
282 %cmp96 = call zeroext i1 @check()
283 br i1 %cmp96, label %if.then97, label %for.cond103
286 br label %for.cond103t
289 br label %for.cond103
292 %cmp105 = call zeroext i1 @check()
293 br i1 %cmp105, label %for.body106, label %for.end120
296 %cmp108 = call zeroext i1 @check()
297 br i1 %cmp108, label %if.then109, label %for.inc117
303 br label %for.cond103t
309 br i1 false, label %for.body22, label %for.cond15.for.inc163_crit_edge
311 for.cond15.for.inc163_crit_edge:
315 %cmp12 = call zeroext i1 @check()
316 br i1 %cmp12, label %for.body, label %for.end166
323 ; Remove a loop whose exit branches into a sibling loop.
324 ; Ensure that only the loop is removed and rely on verify-loopinfo to
327 ; CHECK: @unloopCriticalEdge
328 ; CHECK: while.cond.outer.i.loopexit.split:
329 ; CHECK: br label %while.body
331 ; CHECK: br label %for.end78
332 define void @unloopCriticalEdge() nounwind {
337 br i1 undef, label %for.body35, label %for.end94
340 br label %while.cond.i.preheader
342 while.cond.i.preheader:
343 br i1 undef, label %while.cond.i.preheader.split, label %while.cond.outer.i.loopexit.split
345 while.cond.i.preheader.split:
346 br label %while.cond.i
349 br i1 true, label %while.cond.i, label %while.cond.outer.i.loopexit
351 while.cond.outer.i.loopexit:
352 br label %while.cond.outer.i.loopexit.split
354 while.cond.outer.i.loopexit.split:
355 br i1 false, label %while.cond.i.preheader, label %Func2.exit
361 br i1 false, label %while.body, label %while.end
367 br i1 undef, label %Proc2.exit, label %for.cond.i.preheader
369 for.cond.i.preheader:
382 ; Test UnloopUpdater::removeBlocksFromAncestors.
384 ; Check that the loop backedge is removed from the middle loop 1699,
385 ; but not the inner loop 1676.
386 ; CHECK: while.body1694:
387 ; CHECK: br label %while.cond1676
388 ; CHECK: while.end1699:
389 ; CHECK: br label %sw.default1711
390 define void @removeSubloopBlocks() nounwind {
392 br label %tryagain.outer
394 tryagain.outer: ; preds = %sw.bb304, %entry
397 tryagain: ; preds = %while.end1699, %tryagain.outer
398 br i1 undef, label %sw.bb1669, label %sw.bb304
400 sw.bb304: ; preds = %tryagain
401 br i1 undef, label %return, label %tryagain.outer
403 sw.bb1669: ; preds = %tryagain
404 br i1 undef, label %sw.default1711, label %while.cond1676
406 while.cond1676: ; preds = %while.body1694, %sw.bb1669
407 br i1 undef, label %while.end1699, label %while.body1694
409 while.body1694: ; preds = %while.cond1676
410 br label %while.cond1676
412 while.end1699: ; preds = %while.cond1676
413 br i1 false, label %tryagain, label %sw.default1711
415 sw.default1711: ; preds = %while.end1699, %sw.bb1669, %tryagain
418 defchar: ; preds = %sw.default1711, %sw.bb376
419 br i1 undef, label %if.end2413, label %if.then2368
421 if.then2368: ; preds = %defchar
424 if.end2413: ; preds = %defchar
427 return: ; preds = %sw.bb304