xref: /llvm-project/llvm/test/Transforms/LoopUnroll/runtime-loop-branchweight.ll (revision b30c9c937802a78ef986cb4219eba51148f76e6c)
1; RUN: opt < %s -S -passes=loop-unroll -unroll-runtime=true -unroll-count=4 | FileCheck %s
2
3;; Check that the remainder loop is properly assigned a branch weight for its latch branch.
4; CHECK-LABEL: @test(
5; CHECK-LABEL: for.body:
6; CHECK: br i1 [[COND1:%.*]], label %for.end.loopexit.unr-lcssa.loopexit, label %for.body, !prof ![[#PROF:]], !llvm.loop ![[#LOOP:]]
7; CHECK-LABEL: for.body.epil:
8; CHECK: br i1 [[COND2:%.*]], label  %for.body.epil, label %for.end.loopexit.epilog-lcssa, !prof ![[#PROF2:]], !llvm.loop ![[#LOOP2:]]
9; CHECK: ![[#PROF]] = !{!"branch_weights", i32 1, i32 2499}
10; CHECK: ![[#PROF2]] = !{!"branch_weights", i32 1, i32 1}
11
12define i3 @test(ptr %a, i3 %n) {
13entry:
14  %cmp1 = icmp eq i3 %n, 0
15  br i1 %cmp1, label %for.end, label %for.body
16
17for.body:
18  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
19  %sum.02 = phi i3 [ %add, %for.body ], [ 0, %entry ]
20  %arrayidx = getelementptr inbounds i3, ptr %a, i64 %indvars.iv
21  %0 = load i3, ptr %arrayidx
22  %add = add nsw i3 %0, %sum.02
23  %indvars.iv.next = add i64 %indvars.iv, 1
24  %lftr.wideiv = trunc i64 %indvars.iv.next to i3
25  %exitcond = icmp eq i3 %lftr.wideiv, %n
26  br i1 %exitcond, label %for.end, label %for.body, !prof !0
27
28for.end:
29  %sum.0.lcssa = phi i3 [ 0, %entry ], [ %add, %for.body ]
30  ret i3 %sum.0.lcssa
31}
32
33!0 = !{!"branch_weights", i32 1, i32 9999}
34