1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -S -passes='require<opt-remark-emit>,loop-unroll<peeling;no-runtime>,simplify-cfg,instcombine' -unroll-force-peel-count=3 -verify-dom-info | FileCheck %s
3
4define void @basic(i32 %K, i32 %N) {
5; CHECK-LABEL: @basic(
6; CHECK-NEXT:  entry:
7; CHECK-NEXT:    br label [[OUTER:%.*]]
8; CHECK:       outer:
9; CHECK-NEXT:    [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_INC:%.*]], [[OUTER_BACKEDGE:%.*]] ]
10; CHECK-NEXT:    [[CMP_INNER_PEEL8:%.*]] = icmp sgt i32 [[K:%.*]], 3
11; CHECK-NEXT:    br i1 [[CMP_INNER_PEEL8]], label [[INNER:%.*]], label [[OUTER_BACKEDGE]]
12; CHECK:       inner:
13; CHECK-NEXT:    [[J:%.*]] = phi i32 [ [[J_INC:%.*]], [[INNER]] ], [ 3, [[OUTER]] ]
14; CHECK-NEXT:    [[J_INC]] = add nuw nsw i32 [[J]], 1
15; CHECK-NEXT:    [[CMP_INNER:%.*]] = icmp slt i32 [[J_INC]], [[K]]
16; CHECK-NEXT:    br i1 [[CMP_INNER]], label [[INNER]], label [[OUTER_BACKEDGE]], [[LOOP0:!llvm.loop !.*]]
17; CHECK:       outer.backedge:
18; CHECK-NEXT:    [[I_INC]] = add i32 [[I]], 1
19; CHECK-NEXT:    [[CMP_OUTER:%.*]] = icmp slt i32 [[I_INC]], [[N:%.*]]
20; CHECK-NEXT:    br i1 [[CMP_OUTER]], label [[OUTER]], label [[END:%.*]]
21; CHECK:       end:
22; CHECK-NEXT:    ret void
23;
24entry:
25  br label %outer
26
27outer:
28  %i = phi i32 [ 0, %entry ], [ %i.inc, %outer.backedge ]
29  br label %inner
30
31inner:
32  %j = phi i32 [ 0, %outer ], [ %j.inc, %inner ]
33  %j.inc = add i32 %j, 1
34  %cmp.inner = icmp slt i32 %j.inc, %K
35  br i1 %cmp.inner, label %inner, label %outer.backedge, !llvm.loop !1
36
37outer.backedge:
38  %i.inc = add i32 %i, 1
39  %cmp.outer = icmp slt i32 %i.inc, %N
40  br i1 %cmp.outer, label %outer, label %end
41
42end:
43  ret void
44}
45
46!1 = distinct !{!1}
47