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 3 4declare void @bar() cold 5 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. 9define 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] 16 17entry: 18 br i1 undef, label %l1, label %r1 19 20l1: 21 br i1 undef, label %cold, label %unreached 22 23r1: 24 br i1 undef, label %unreached, label %cold 25 26unreached: 27 unreachable 28 29cold: 30 call void @bar() 31 ret void 32} 33 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. 37define 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] 44 45entry: 46 br i1 undef, label %l1, label %r1 47 48l1: 49 br i1 undef, label %cold, label %cold2 50 51r1: 52 br i1 undef, label %unreached, label %cold 53 54unreached: 55 unreachable 56 57cold: 58 call void @bar() 59 ret void 60 61cold2: 62 call void @bar() 63 ret void 64} 65 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. 68define 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% 75 76entry: 77 br i1 undef, label %l1, label %r1 78 79l1: 80 br i1 undef, label %cold, label %unreached 81 82r1: 83 br i1 undef, label %unreached, label %unreached2 84 85unreached: 86 unreachable 87 88unreached2: 89 unreachable 90 91cold: 92 call void @bar() 93 ret void 94} 95 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. 99define 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] 107 108entry: 109 br i1 undef, label %l1, label %r1 110 111l1: 112 br i1 undef, label %l2, label %r2 113 114l2: 115 br label %to.cold 116 117r2: 118 br label %to.cold 119 120to.cold: 121 br label %cold 122 123r1: 124 ret void 125 126cold: 127 call void @bar() 128 ret void 129} 130 131; Check that most likely path from 'entry' to 'l2' through 'r1' is preferred. 132define 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% 138 139entry: 140 br i1 undef, label %cold, label %r1 141 142cold: 143 call void @bar() 144 br label %l2 145 146r1: 147 br i1 undef, label %l2, label %unreached 148 149l2: 150 ret void 151 152unreached: 153 unreachable 154} 155