xref: /llvm-project/llvm/test/Transforms/LoopUnroll/unroll-heuristics-pgo.ll (revision b30c9c937802a78ef986cb4219eba51148f76e6c)
1; RUN: opt < %s -S -passes=loop-unroll -unroll-runtime -unroll-threshold=40 -unroll-max-percent-threshold-boost=100 | FileCheck %s
2
3@known_constant = internal unnamed_addr constant [9 x i32] [i32 0, i32 -1, i32 0, i32 -1, i32 5, i32 -1, i32 0, i32 -1, i32 0], align 16
4
5; CHECK-LABEL: @bar_prof
6; CHECK: loop:
7; CHECK:   %mul = mul
8; CHECK:   %mul.1 = mul
9; CHECK:   %mul.2 = mul
10; CHECK:   %mul.3 = mul
11; CHECK:   br i1 %niter.ncmp.7, label %loop.end.unr-lcssa.loopexit, label %loop, !prof [[PROF0:![0-9]+]]
12; CHECK: loop.epil:
13; CHECK:   br i1 %epil.iter.cmp, label %loop.epil, label %loop.end.epilog-lcssa, !prof [[PROF1:![0-9]+]], !llvm.loop {{![0-9]+}}
14define i32 @bar_prof(ptr noalias nocapture readonly %src, i64 %c) !prof !1 {
15entry:
16  br label %loop
17
18loop:
19  %iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
20  %r  = phi i32 [ 0, %entry ], [ %add, %loop ]
21  %arrayidx = getelementptr inbounds i32, ptr %src, i64 %iv
22  %src_element = load i32, ptr %arrayidx, align 4
23  %array_const_idx = getelementptr inbounds [9 x i32], ptr @known_constant, i64 0, i64 %iv
24  %const_array_element = load i32, ptr %array_const_idx, align 4
25  %mul = mul nsw i32 %src_element, %const_array_element
26  %add = add nsw i32 %mul, %r
27  %inc = add nuw nsw i64 %iv, 1
28  %exitcond86.i = icmp eq i64 %inc, %c
29  br i1 %exitcond86.i, label %loop.end, label %loop, !prof !2
30
31loop.end:
32  %r.lcssa = phi i32 [ %r, %loop ]
33  ret i32 %r.lcssa
34}
35
36; CHECK-LABEL: @bar_prof_flat
37; CHECK-NOT: loop.epil
38define i32 @bar_prof_flat(ptr noalias nocapture readonly %src, i64 %c) !prof !1 {
39entry:
40  br label %loop
41
42loop:
43  %iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
44  %r  = phi i32 [ 0, %entry ], [ %add, %loop ]
45  %arrayidx = getelementptr inbounds i32, ptr %src, i64 %iv
46  %src_element = load i32, ptr %arrayidx, align 4
47  %array_const_idx = getelementptr inbounds [9 x i32], ptr @known_constant, i64 0, i64 %iv
48  %const_array_element = load i32, ptr %array_const_idx, align 4
49  %mul = mul nsw i32 %src_element, %const_array_element
50  %add = add nsw i32 %mul, %r
51  %inc = add nuw nsw i64 %iv, 1
52  %exitcond86.i = icmp eq i64 %inc, %c
53  br i1 %exitcond86.i, label %loop, label %loop.end, !prof !2
54
55loop.end:
56  %r.lcssa = phi i32 [ %r, %loop ]
57  ret i32 %r.lcssa
58}
59
60!1 = !{!"function_entry_count", i64 1}
61!2 = !{!"branch_weights", i32 1, i32 1000}
62
63; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 124}
64; CHECK: [[PROF1]] = !{!"branch_weights", i32 3, i32 1}
65