1; RUN: opt < %s -S -loop-unroll -unroll-force-peel-count=1 | FileCheck %s
2
3; Check we don't peel loops where the latch is not the exiting block.
4; CHECK-LABEL: @invariant_backedge_irreducible
5; CHECK: entry:
6; CHECK: br label %header
7; CHECK-NOT: peel
8; CHECK: header:
9; CHECK: br i1 {{.*}} label %latch, label %exiting
10; CHECK: latch:
11; CHECK: br i1 {{.*}} label %header, label %exiting
12; CHECK: exiting:
13; CHECK: br i1 {{.*}} label %latch, label %exit
14
15define i32 @invariant_backedge_irreducible(i32 %a, i32 %b) {
16entry:
17  br label %header
18
19header:
20  %i = phi i32 [ 0, %entry ], [ %inc, %latch ]
21  %cmp.phi = phi i1 [ false, %entry ], [ %cmp, %latch ]
22  br i1 %cmp.phi, label %latch, label %exiting
23
24latch:
25  %inc = add i32 %i, 1
26  %cmp = icmp slt i32 %i, 1000
27  br i1 %cmp, label %header, label %exiting
28
29exiting:
30  %cmp.exiting = phi i1 [ %cmp.phi, %header ], [ %cmp, %latch ]
31  br i1 %cmp.exiting, label %latch, label %exit
32
33exit:
34  ret i32 0
35}
36
37