1; RUN: opt -loop-unroll -unroll-allow-partial -S %s -verify-loop-info -verify-dom-info -verify-loop-lcssa | FileCheck %s
2
3@table = internal unnamed_addr global [344 x i32] zeroinitializer, align 16
4
5define i32 @test_partial_unroll_with_breakout_at_iter0() {
6; CHECK-LABEL: define i32 @test_partial_unroll_with_breakout_at_iter0() {
7; CHECK-LABEL: entry:
8; CHECK-NEXT:    br label %for.header
9
10; CHECK-LABEL: for.header:                                       ; preds = %for.latch.3, %entry
11; CHECK-NEXT:    %red = phi i32 [ 0, %entry ], [ %red.next.3, %for.latch.3 ]
12; CHECK-NEXT:    %iv = phi i64 [ 0, %entry ], [ %iv.next.3, %for.latch.3 ]
13; CHECK-NEXT:    %red.next = add nuw nsw i32 10, %red
14; CHECK-NEXT:    %iv.next = add nuw nsw i64 %iv, 2
15; CHECK-NEXT:    %ptr = getelementptr inbounds [344 x i32], [344 x i32]* @table, i64 0, i64 %iv.next
16; CHECK-NEXT:    store i32 %red.next, i32* %ptr, align 4
17; CHECK-NEXT:    br label %for.latch
18
19; CHECK-LABEL: for.latch:                                        ; preds = %for.header
20; CHECK-NEXT:    %red.next.1 = add nuw nsw i32 10, %red.next
21; CHECK-NEXT:    %iv.next.1 = add nuw nsw i64 %iv.next, 2
22; CHECK-NEXT:    %ptr.1 = getelementptr inbounds [344 x i32], [344 x i32]* @table, i64 0, i64 %iv.next.1
23; CHECK-NEXT:    store i32 %red.next.1, i32* %ptr.1, align 4
24; CHECK-NEXT:    br label %for.latch.1
25
26; CHECK-LABEL: exit:                                             ; preds = %for.latch.2
27; CHECK-NEXT:    ret i32 0
28
29; CHECK-LABEL: for.latch.1:                                      ; preds = %for.latch
30; CHECK-NEXT:    %red.next.2 = add nuw nsw i32 10, %red.next.1
31; CHECK-NEXT:    %iv.next.2 = add nuw nsw i64 %iv.next.1, 2
32; CHECK-NEXT:    %ptr.2 = getelementptr inbounds [344 x i32], [344 x i32]* @table, i64 0, i64 %iv.next.2
33; CHECK-NEXT:    store i32 %red.next.2, i32* %ptr.2, align 4
34; CHECK-NEXT:    br label %for.latch.2
35
36; CHECK-LABEL: for.latch.2:                                      ; preds = %for.latch.1
37; CHECK-NEXT:    %red.next.3 = add nuw nsw i32 10, %red.next.2
38; CHECK-NEXT:    %iv.next.3 = add nuw nsw i64 %iv.next.2, 2
39; CHECK-NEXT:    %ptr.3 = getelementptr inbounds [344 x i32], [344 x i32]* @table, i64 0, i64 %iv.next.3
40; CHECK-NEXT:    store i32 %red.next.3, i32* %ptr.3, align 4
41; CHECK-NEXT:    %exitcond.1.i.3 = icmp eq i64 %iv.next.3, 344
42; CHECK-NEXT:    br i1 %exitcond.1.i.3, label %exit, label %for.latch.3
43
44; CHECK-LABEL: for.latch.3:                                      ; preds = %for.latch.2
45; CHECK-NEXT:    br label %for.header
46;
47entry:
48  br label %for.header
49
50for.header:                                     ; preds = %for.body28.i.for.body28.i_crit_edge, %for.body.i
51  %red = phi i32 [ 0, %entry ], [ %red.next, %for.latch ]
52  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.latch ]
53  %red.next = add i32 10, %red
54  %iv.next = add nuw nsw i64 %iv, 2
55  %ptr = getelementptr inbounds [344 x i32], [344 x i32]* @table, i64 0, i64 %iv.next
56  store i32 %red.next, i32* %ptr, align 4
57  %exitcond.1.i = icmp eq i64 %iv.next, 344
58  br i1 %exitcond.1.i, label %exit, label %for.latch
59
60for.latch:              ; preds = %for.header
61  br label %for.header
62
63exit:
64  ret i32 0
65}
66