1 ; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
3 define i32 @test1(i32 %i, ptr %a) {
4 ; CHECK-LABEL: Printing analysis {{.*}} for function 'test1':
5 ; CHECK-NEXT: block-frequency-info: test1
6 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
10 ; Loop backedges are weighted and thus their bodies have a greater frequency.
11 ; CHECK-NEXT: body: float = 32.0,
13 %iv = phi i32 [ 0, %entry ], [ %next, %body ]
14 %base = phi i32 [ 0, %entry ], [ %sum, %body ]
15 %arrayidx = getelementptr inbounds i32, ptr %a, i32 %iv
16 %0 = load i32, ptr %arrayidx
17 %sum = add nsw i32 %0, %base
18 %next = add i32 %iv, 1
19 %exitcond = icmp eq i32 %next, %i
20 br i1 %exitcond, label %exit, label %body
22 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
27 define i32 @test2(i32 %i, i32 %a, i32 %b) {
28 ; CHECK-LABEL: Printing analysis {{.*}} for function 'test2':
29 ; CHECK-NEXT: block-frequency-info: test2
30 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
32 %cond = icmp ult i32 %i, 42
33 br i1 %cond, label %then, label %else, !prof !0
35 ; The 'then' branch is predicted more likely via branch weight metadata.
36 ; CHECK-NEXT: then: float = 0.9411{{[0-9]*}},
40 ; CHECK-NEXT: else: float = 0.05882{{[0-9]*}},
44 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
46 %result = phi i32 [ %a, %then ], [ %b, %else ]
50 !0 = !{!"branch_weights", i32 64, i32 4}
52 define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) {
53 ; CHECK-LABEL: Printing analysis {{.*}} for function 'test3':
54 ; CHECK-NEXT: block-frequency-info: test3
55 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
57 switch i32 %i, label %case_a [ i32 1, label %case_b
60 i32 4, label %case_e ], !prof !1
62 ; CHECK-NEXT: case_a: float = 0.05,
66 ; CHECK-NEXT: case_b: float = 0.05,
70 ; The 'case_c' branch is predicted more likely via branch weight metadata.
71 ; CHECK-NEXT: case_c: float = 0.8,
75 ; CHECK-NEXT: case_d: float = 0.05,
79 ; CHECK-NEXT: case_e: float = 0.05,
83 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
85 %result = phi i32 [ %a, %case_a ],
93 !1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4}
95 define void @nested_loops(i32 %a) {
96 ; CHECK-LABEL: Printing analysis {{.*}} for function 'nested_loops':
97 ; CHECK-NEXT: block-frequency-info: nested_loops
98 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
100 br label %for.cond1.preheader
102 ; CHECK-NEXT: for.cond1.preheader: float = 4001.0,
104 %x.024 = phi i32 [ 0, %entry ], [ %inc12, %for.inc11 ]
105 br label %for.cond4.preheader
107 ; CHECK-NEXT: for.cond4.preheader: float = 16007984.8,
109 %y.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc9, %for.inc8 ]
110 %add = add i32 %y.023, %x.024
113 ; CHECK-NEXT: for.body6: float = 64047914563.9,
115 %z.022 = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.body6 ]
116 %add7 = add i32 %add, %z.022
117 tail call void @g(i32 %add7)
118 %inc = add i32 %z.022, 1
119 %cmp5 = icmp ugt i32 %inc, %a
120 br i1 %cmp5, label %for.inc8, label %for.body6, !prof !2
122 ; CHECK-NEXT: for.inc8: float = 16007984.8,
124 %inc9 = add i32 %y.023, 1
125 %cmp2 = icmp ugt i32 %inc9, %a
126 br i1 %cmp2, label %for.inc11, label %for.cond4.preheader, !prof !2
128 ; CHECK-NEXT: for.inc11: float = 4001.0,
130 %inc12 = add i32 %x.024, 1
131 %cmp = icmp ugt i32 %inc12, %a
132 br i1 %cmp, label %for.end13, label %for.cond1.preheader, !prof !2
134 ; CHECK-NEXT: for.end13: float = 1.0, int = [[ENTRY]]
141 !2 = !{!"branch_weights", i32 1, i32 4000}