1 ; RUN: opt -analyze -branch-prob < %s -enable-new-pm=0 | FileCheck %s
2 ; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
4 declare void @bar() cold
6 ; Both 'l1' and 'r1' has one edge leading to 'cold' and another one to
7 ; 'unreachable' blocks. Check that 'cold' paths are preferred. Also ensure both
8 ; paths from 'entry' block are equal.
9 define void @test1(i32 %0) {
10 ;CHECK: edge entry -> l1 probability is 0x40000000 / 0x80000000 = 50.00%
11 ;CHECK: edge entry -> r1 probability is 0x40000000 / 0x80000000 = 50.00%
12 ;CHECK: edge l1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
13 ;CHECK: edge l1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
14 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
15 ;CHECK: edge r1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
18 br i1 undef, label %l1, label %r1
21 br i1 undef, label %cold, label %unreached
24 br i1 undef, label %unreached, label %cold
34 ; Both edges of 'l1' leads to 'cold' blocks while one edge of 'r1' leads to
35 ; 'unreachable' block. Check that 'l1' has 50/50 while 'r1' has 0/100
36 ; distributuion. Also ensure both paths from 'entry' block are equal.
37 define void @test2(i32 %0) {
38 ;CHECK: edge entry -> l1 probability is 0x40000000 / 0x80000000 = 50.00%
39 ;CHECK: edge entry -> r1 probability is 0x40000000 / 0x80000000 = 50.00%
40 ;CHECK: edge l1 -> cold probability is 0x40000000 / 0x80000000 = 50.00%
41 ;CHECK: edge l1 -> cold2 probability is 0x40000000 / 0x80000000 = 50.00%
42 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
43 ;CHECK: edge r1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
46 br i1 undef, label %l1, label %r1
49 br i1 undef, label %cold, label %cold2
52 br i1 undef, label %unreached, label %cold
66 ; Both edges of 'r1' leads to 'unreachable' blocks while one edge of 'l1' leads to
67 ; 'cold' block. Ensure that path leading to 'cold' block is preferred.
68 define void @test3(i32 %0) {
69 ;CHECK: edge entry -> l1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
70 ;CHECK: edge entry -> r1 probability is 0x00000000 / 0x80000000 = 0.00%
71 ;CHECK: edge l1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
72 ;CHECK: edge l1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
73 ;CHECK: edge r1 -> unreached probability is 0x40000000 / 0x80000000 = 50.00%
74 ;CHECK: edge r1 -> unreached2 probability is 0x40000000 / 0x80000000 = 50.00%
77 br i1 undef, label %l1, label %r1
80 br i1 undef, label %cold, label %unreached
83 br i1 undef, label %unreached, label %unreached2
96 ; Left edge of 'entry' leads to 'cold' block while right edge is 'normal' continuation.
97 ; Check that we able to propagate 'cold' weight to 'entry' block. Also ensure
98 ; both edges from 'l1' are equally likely.
99 define void @test4(i32 %0) {
100 ;CHECK: edge entry -> l1 probability is 0x078780e3 / 0x80000000 = 5.88%
101 ;CHECK: edge entry -> r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
102 ;CHECK: edge l1 -> l2 probability is 0x40000000 / 0x80000000 = 50.00%
103 ;CHECK: edge l1 -> r2 probability is 0x40000000 / 0x80000000 = 50.00%
104 ;CHECK: edge l2 -> to.cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
105 ;CHECK: edge r2 -> to.cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
106 ;CHECK: edge to.cold -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
109 br i1 undef, label %l1, label %r1
112 br i1 undef, label %l2, label %r2
131 ; Check that most likely path from 'entry' to 'l2' through 'r1' is preferred.
132 define void @test5(i32 %0) {
133 ;CHECK: edge entry -> cold probability is 0x078780e3 / 0x80000000 = 5.88%
134 ;CHECK: edge entry -> r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
135 ;CHECK: edge cold -> l2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
136 ;CHECK: edge r1 -> l2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
137 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
140 br i1 undef, label %cold, label %r1
147 br i1 undef, label %l2, label %unreached