1 ; RUN: opt < %s -S -passes='require<opt-remark-emit>,unroll<peeling;no-runtime>,simplify-cfg,instcombine' -unroll-force-peel-count=3 -verify-dom-info | FileCheck %s
3 define void @basic(i32 %K, i32 %N) {
6 ; CHECK-NEXT: br label [[OUTER:%.*]]
8 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[OUTER_BACKEDGE:%.*]] ]
9 ; CHECK-NEXT: [[CMP_INNER_PEEL:%.*]] = icmp sgt i32 [[K:%.*]], 1
10 ; CHECK-NEXT: br i1 [[CMP_INNER_PEEL]], label [[INNER_PEEL2:%.*]], label [[OUTER_BACKEDGE]]
12 ; CHECK-NEXT: [[CMP_INNER_PEEL4:%.*]] = icmp eq i32 [[K]], 2
13 ; CHECK-NEXT: br i1 [[CMP_INNER_PEEL4]], label [[OUTER_BACKEDGE]], label [[INNER_PEEL6:%.*]]
15 ; CHECK-NEXT: [[CMP_INNER_PEEL8:%.*]] = icmp sgt i32 [[K]], 3
16 ; CHECK-NEXT: br i1 [[CMP_INNER_PEEL8]], label [[INNER:%.*]], label [[OUTER_BACKEDGE]]
18 ; CHECK-NEXT: [[J:%.*]] = phi i32 [ [[J_INC:%.*]], [[INNER]] ], [ 3, [[INNER_PEEL6]] ]
19 ; CHECK-NEXT: [[J_INC]] = add nuw nsw i32 [[J]], 1
20 ; CHECK-NEXT: [[CMP_INNER:%.*]] = icmp slt i32 [[J_INC]], [[K]]
21 ; CHECK-NEXT: br i1 [[CMP_INNER]], label [[INNER]], label [[OUTER_BACKEDGE]], !llvm.loop !0
22 ; CHECK: outer.backedge:
23 ; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
24 ; CHECK-NEXT: [[CMP_OUTER:%.*]] = icmp slt i32 [[I_INC]], [[N:%.*]]
25 ; CHECK-NOT: !llvm.loop
32 %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.backedge ]
36 %j = phi i32 [ 0, %outer ], [ %j.inc, %inner ]
37 %j.inc = add i32 %j, 1
38 %cmp.inner = icmp slt i32 %j.inc, %K
39 br i1 %cmp.inner, label %inner, label %outer.backedge, !llvm.loop !1
42 %i.inc = add i32 %i, 1
43 %cmp.outer = icmp slt i32 %i.inc, %N
44 br i1 %cmp.outer, label %outer, label %end