1 ; RUN: opt < %s -loop-unroll -S | FileCheck %s
2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4 ; This test shows how unrolling an inner loop could break LCSSA for an outer
5 ; loop, and there is no cheap way to recover it.
7 ; In this case the inner loop, L3, is being unrolled. It only runs one
8 ; iteration, so unrolling basically means replacing
9 ; br i1 true, label %exit, label %L3_header
13 ; However, this change messes up the loops structure: for instance, block
14 ; L3_body no longer belongs to L2. It becomes an exit block for L2, so LCSSA
15 ; phis for definitions in L2 should now be placed there. In particular, we need
16 ; to insert such a definition for %y1.
27 %y1 = phi i64 [ undef, %L1_header ], [ %x.lcssa, %L2_latch ]
31 %y2 = phi i64 [ 0, %L3_latch ], [ %y1, %L2_header ]
32 %x = add i64 undef, -1
33 br i1 true, label %L2_latch, label %L3_body
36 %x.lcssa = phi i64 [ %x, %L3_header ]
40 ; CHECK-NEXT: %y1.lcssa = phi i64 [ %y1, %L3_header ]
42 store i64 %y1, i64* undef
43 br i1 false, label %L3_latch, label %L1_latch
46 br i1 true, label %exit, label %L3_header
49 %y.lcssa = phi i64 [ %y2, %L3_body ]
56 ; Additional tests for some corner cases.
67 %a = phi i64 [ undef, %L1_header ], [ %dec_us, %L3_header ]
71 %b = phi i64 [ 0, %L3_latch ], [ %a, %L2_header ]
72 %dec_us = add i64 undef, -1
73 br i1 true, label %L2_header, label %L3_break_to_L1
75 ; CHECK: L3_break_to_L1:
76 ; CHECK-NEXT: %a.lcssa = phi i64 [ %a, %L3_header ]
78 br i1 false, label %L3_latch, label %L1_latch
81 %b_lcssa = phi i64 [ %b, %L3_break_to_L1 ]
85 br i1 true, label %Exit, label %L3_header
97 %a = phi i8* [ %b, %L1_latch ], [ null, %entry ]
98 br i1 undef, label %L2_header, label %L1_latch
101 br i1 undef, label %L2_latch, label %L1_latch
104 ; CHECK-NEXT: %a.lcssa = phi i8* [ %a, %L2_header ]
106 br i1 true, label %L2_exit, label %L2_header
109 %b = phi i8* [ undef, %L1_header ], [ null, %L2_header ]
113 %a_lcssa1 = phi i8* [ %a, %L2_latch ]
117 %a_lcssa2 = phi i8* [ %a_lcssa1, %L2_exit ]
128 %x = icmp eq i32 1, 0
135 br i1 true, label %L2_header, label %L3_exiting
138 br i1 true, label %L3_body, label %L1_latch
141 ; CHECK-NEXT: %x.lcssa = phi i1
143 br i1 %x, label %L3_latch, label %L3_latch
146 br i1 false, label %L3_header, label %exit
156 define void @foo5() {
164 ; CHECK-NOT: br i1 true
165 ; CHECK: br label %inner2_indirect_exit
167 br i1 true, label %inner2_indirect_exit.preheader, label %inner1
169 inner2_indirect_exit.preheader:
170 br label %inner2_indirect_exit
172 inner2_indirect_exit:
173 %a = phi i32 [ %b, %inner2_latch ], [ undef, %inner2_indirect_exit.preheader ]
174 indirectbr i8* undef, [label %inner2_latch, label %inner3, label %outer_latch]
177 %b = load i32, i32* undef, align 8
178 br label %inner2_indirect_exit
181 %a.lcssa = phi i32 [ %a.lcssa, %inner3 ], [ %a, %inner2_indirect_exit ]
182 br i1 true, label %outer_latch.loopexit, label %inner3
184 outer_latch.loopexit:
185 %a.lcssa.lcssa = phi i32 [ %a.lcssa, %inner3 ]
186 br label %outer_latch