1 ; RUN: opt < %s -lcssa -loop-simplify -indvars -S | FileCheck %s
2 target triple = "x86_64-unknown-linux-gnu"
5 ; When LoopSimplify separates nested loops, it might break LCSSA form: values
6 ; from the original loop might be used in the outer loop. This test invokes
7 ; loop-unroll, which calls loop-simplify before itself. If LCSSA is broken
8 ; after loop-simplify, we crash on assertion.
19 br i1 true, label %loop1, label %bb43
22 %a = phi i32 [ undef, %loop1 ], [ 0, %bb45 ], [ %a, %bb54 ]
23 %b = phi i32 [ 0, %loop1 ], [ 1, %bb54 ], [ %c, %bb45 ]
24 br i1 true, label %bb114, label %header
29 br i1 true, label %bb45, label %bb54
51 br i1 true, label %loop1, label %loop2.preheader
54 %a.ph = phi i32 [ undef, %loop1 ]
55 %b.ph = phi i32 [ 0, %loop1 ]
59 %a = phi i32 [ 0, %loop2.if.true ], [ %a, %loop2.if.false ], [ %a.ph, %loop2.preheader ], [0, %bb]
60 %b = phi i32 [ 1, %loop2.if.false ], [ %c, %loop2.if.true ], [ %b.ph, %loop2.preheader ], [%c, %bb]
61 br i1 true, label %loop2.if, label %outer.loopexit
65 switch i32 undef, label %loop2.if.false [i32 0, label %loop2.if.true
69 br i1 undef, label %loop2, label %bb
78 ; When LoopSimplify separates nested loops, it might break LCSSA form: values
79 ; from the original loop might be used in exit blocks of the outer loop.
86 br i1 undef, label %bb2, label %bb1
89 %a = phi i32 [ undef, %bb1 ], [ %a, %bb3 ], [ undef, %bb5 ]
90 br i1 undef, label %bb3, label %bb1
93 %b = load i32*, i32** undef
94 br i1 undef, label %bb2, label %bb4
97 br i1 undef, label %bb5, label %bb6
100 br i1 undef, label %bb2, label %bb4
103 br i1 undef, label %bb_end, label %bb1
106 %x = getelementptr i32, i32* %b
110 ; When LoopSimplify separates nested loops, it might break LCSSA form: values
111 ; from the original loop might occur in a loop, which is now a sibling of the
112 ; original loop (before separating it was a subloop of the original loop, and
113 ; thus didn't require an lcssa phi nodes).
115 define void @foo4() {
119 ; CHECK: bb2.loopexit:
120 bb2.loopexit: ; preds = %bb3
121 %i.ph = phi i32 [ 0, %bb3 ]
126 bb2: ; preds = %bb2.loopexit, %bb2, %bb1
127 %i = phi i32 [ 0, %bb1 ], [ %i, %bb2 ], [ %i.ph, %bb2.loopexit ]
128 %x = load i32, i32* undef, align 8
129 br i1 undef, label %bb2, label %bb3.preheader
131 ; CHECK: bb3.preheader:
132 bb3.preheader: ; preds = %bb2
133 ; CHECK: %x.lcssa = phi i32 [ %x, %bb2 ]
136 bb3: ; preds = %bb3.preheader, %bb3
138 br i1 true, label %bb2.loopexit, label %bb3