1; RUN: opt < %s -analyze -block-freq -enable-new-pm=0 | FileCheck %s
2; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
3
4declare void @g(i32 %x)
5
6; CHECK-LABEL: Printing analysis {{.*}} for function 'branch_weight_0':
7; CHECK-NEXT: block-frequency-info: branch_weight_0
8define void @branch_weight_0(i32 %a) {
9; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
10entry:
11  br label %for.body
12
13; Check that we get 1 and a huge frequency instead of 0,3.
14; CHECK-NEXT: for.body: float = 2147483647.8,
15for.body:
16  %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
17  call void @g(i32 %i)
18  %inc = add i32 %i, 1
19  %cmp = icmp ugt i32 %inc, %a
20  br i1 %cmp, label %for.end, label %for.body, !prof !0
21
22; CHECK-NEXT: for.end: float = 1.0, int = [[ENTRY]]
23for.end:
24  ret void
25}
26
27!0 = !{!"branch_weights", i32 0, i32 3}
28
29; CHECK-LABEL: Printing analysis {{.*}} for function 'infinite_loop'
30; CHECK-NEXT: block-frequency-info: infinite_loop
31define void @infinite_loop(i1 %x) {
32; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
33entry:
34  br i1 %x, label %for.body, label %for.end, !prof !1
35
36; Check that the infinite loop is arbitrarily scaled to max out at 4096,
37; giving 2048 here.
38; CHECK-NEXT: for.body: float = 2048.0,
39for.body:
40  %i = phi i32 [ 0, %entry ], [ %inc, %for.body ]
41  call void @g(i32 %i)
42  %inc = add i32 %i, 1
43  br label %for.body
44
45; Check that the exit weight is half of entry, since half is lost in the
46; infinite loop above.
47; CHECK-NEXT: for.end: float = 0.5,
48for.end:
49  ret void
50}
51
52!1 = !{!"branch_weights", i32 1, i32 1}
53