1 ; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
3 declare void @bar() cold
5 ; Both 'l1' and 'r1' has one edge leading to 'cold' and another one to
6 ; 'unreachable' blocks. Check that 'cold' paths are preferred. Also ensure both
7 ; paths from 'entry' block are equal.
8 define void @test1(i32 %0) {
9 ;CHECK: edge entry -> l1 probability is 0x40000000 / 0x80000000 = 50.00%
10 ;CHECK: edge entry -> r1 probability is 0x40000000 / 0x80000000 = 50.00%
11 ;CHECK: edge l1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
12 ;CHECK: edge l1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
13 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
14 ;CHECK: edge r1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
17 br i1 undef, label %l1, label %r1
20 br i1 undef, label %cold, label %unreached
23 br i1 undef, label %unreached, label %cold
33 ; Both edges of 'l1' leads to 'cold' blocks while one edge of 'r1' leads to
34 ; 'unreachable' block. Check that 'l1' has 50/50 while 'r1' has 0/100
35 ; distributuion. Also ensure both paths from 'entry' block are equal.
36 define void @test2(i32 %0) {
37 ;CHECK: edge entry -> l1 probability is 0x40000000 / 0x80000000 = 50.00%
38 ;CHECK: edge entry -> r1 probability is 0x40000000 / 0x80000000 = 50.00%
39 ;CHECK: edge l1 -> cold probability is 0x40000000 / 0x80000000 = 50.00%
40 ;CHECK: edge l1 -> cold2 probability is 0x40000000 / 0x80000000 = 50.00%
41 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
42 ;CHECK: edge r1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
45 br i1 undef, label %l1, label %r1
48 br i1 undef, label %cold, label %cold2
51 br i1 undef, label %unreached, label %cold
65 ; Both edges of 'r1' leads to 'unreachable' blocks while one edge of 'l1' leads to
66 ; 'cold' block. Ensure that path leading to 'cold' block is preferred.
67 define void @test3(i32 %0) {
68 ;CHECK: edge entry -> l1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
69 ;CHECK: edge entry -> r1 probability is 0x00000000 / 0x80000000 = 0.00%
70 ;CHECK: edge l1 -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
71 ;CHECK: edge l1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
72 ;CHECK: edge r1 -> unreached probability is 0x40000000 / 0x80000000 = 50.00%
73 ;CHECK: edge r1 -> unreached2 probability is 0x40000000 / 0x80000000 = 50.00%
76 br i1 undef, label %l1, label %r1
79 br i1 undef, label %cold, label %unreached
82 br i1 undef, label %unreached, label %unreached2
95 ; Left edge of 'entry' leads to 'cold' block while right edge is 'normal' continuation.
96 ; Check that we able to propagate 'cold' weight to 'entry' block. Also ensure
97 ; both edges from 'l1' are equally likely.
98 define void @test4(i32 %0) {
99 ;CHECK: edge entry -> l1 probability is 0x078780e3 / 0x80000000 = 5.88%
100 ;CHECK: edge entry -> r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
101 ;CHECK: edge l1 -> l2 probability is 0x40000000 / 0x80000000 = 50.00%
102 ;CHECK: edge l1 -> r2 probability is 0x40000000 / 0x80000000 = 50.00%
103 ;CHECK: edge l2 -> to.cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
104 ;CHECK: edge r2 -> to.cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
105 ;CHECK: edge to.cold -> cold probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
108 br i1 undef, label %l1, label %r1
111 br i1 undef, label %l2, label %r2
130 ; Check that most likely path from 'entry' to 'l2' through 'r1' is preferred.
131 define void @test5(i32 %0) {
132 ;CHECK: edge entry -> cold probability is 0x078780e3 / 0x80000000 = 5.88%
133 ;CHECK: edge entry -> r1 probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
134 ;CHECK: edge cold -> l2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
135 ;CHECK: edge r1 -> l2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
136 ;CHECK: edge r1 -> unreached probability is 0x00000000 / 0x80000000 = 0.00%
139 br i1 undef, label %cold, label %r1
146 br i1 undef, label %l2, label %unreached