1 ; RUN: opt < %s -S -debug-only=loop-unroll -loop-unroll -unroll-allow-peeling 2>&1 | FileCheck %s
4 ; Make sure we use the profile information correctly to peel-off 3 iterations
5 ; from the loop, and update the branch weights for the peeled loop properly.
7 ; CHECK: Loop Unroll: F[basic]
8 ; CHECK: PEELING loop %for.body with iteration count 3!
9 ; CHECK: Loop Unroll: F[optsize]
13 ; CHECK: br i1 %{{.*}}, label %[[NEXT0:.*]], label %for.cond.for.end_crit_edge, !prof !1
15 ; CHECK: br i1 %{{.*}}, label %[[NEXT1:.*]], label %for.cond.for.end_crit_edge, !prof !2
17 ; CHECK: br i1 %{{.*}}, label %[[NEXT2:.*]], label %for.cond.for.end_crit_edge, !prof !3
19 ; CHECK: br i1 %{{.*}}, label %for.body, label %{{.*}}, !prof !4
21 define void @basic(i32* %p, i32 %k) #0 !prof !0 {
23 %cmp3 = icmp slt i32 0, %k
24 br i1 %cmp3, label %for.body.lr.ph, label %for.end
26 for.body.lr.ph: ; preds = %entry
29 for.body: ; preds = %for.body.lr.ph, %for.body
30 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
31 %p.addr.04 = phi i32* [ %p, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]
32 %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.04, i32 1
33 store i32 %i.05, i32* %p.addr.04, align 4
34 %inc = add nsw i32 %i.05, 1
35 %cmp = icmp slt i32 %inc, %k
36 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !prof !1
38 for.cond.for.end_crit_edge: ; preds = %for.body
41 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
45 ; We don't want to peel loops when optimizing for size.
46 ; CHECK-LABEL: @optsize
47 ; CHECK: for.body.lr.ph:
48 ; CHECK-NEXT: br label %for.body
51 ; CHECK: br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
52 define void @optsize(i32* %p, i32 %k) #1 !prof !0 {
54 %cmp3 = icmp slt i32 0, %k
55 br i1 %cmp3, label %for.body.lr.ph, label %for.end
57 for.body.lr.ph: ; preds = %entry
60 for.body: ; preds = %for.body.lr.ph, %for.body
61 %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
62 %p.addr.04 = phi i32* [ %p, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]
63 %incdec.ptr = getelementptr inbounds i32, i32* %p.addr.04, i32 1
64 store i32 %i.05, i32* %p.addr.04, align 4
65 %inc = add nsw i32 %i.05, 1
66 %cmp = icmp slt i32 %inc, %k
67 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge, !prof !1
69 for.cond.for.end_crit_edge: ; preds = %for.body
72 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
76 attributes #0 = { nounwind }
77 attributes #1 = { nounwind optsize }
79 !0 = !{!"function_entry_count", i64 1}
80 !1 = !{!"branch_weights", i32 3001, i32 1001}
82 ;CHECK: !1 = !{!"branch_weights", i32 900, i32 101}
83 ;CHECK: !2 = !{!"branch_weights", i32 540, i32 360}
84 ;CHECK: !3 = !{!"branch_weights", i32 162, i32 378}
85 ;CHECK: !4 = !{!"branch_weights", i32 1399, i32 162}