1 ; Test the static branch probability heuristics for no-return functions.
2 ; RUN: opt < %s -analyze -branch-prob | FileCheck %s
4 declare void @abort() noreturn
6 define i32 @test1(i32 %a, i32 %b) {
7 ; CHECK: Printing analysis {{.*}} for function 'test1'
9 %cond = icmp eq i32 %a, 42
10 br i1 %cond, label %exit, label %abort
11 ; CHECK: edge entry -> exit probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
12 ; CHECK: edge entry -> abort probability is 0x00000800 / 0x80000000 = 0.00%
15 call void @abort() noreturn
22 define i32 @test2(i32 %a, i32 %b) {
23 ; CHECK: Printing analysis {{.*}} for function 'test2'
25 switch i32 %a, label %exit [i32 1, label %case_a
29 ; CHECK: edge entry -> exit probability is 0x7fffe000 / 0x80000000 = 100.00% [HOT edge]
30 ; CHECK: edge entry -> case_a probability is 0x00000800 / 0x80000000 = 0.00%
31 ; CHECK: edge entry -> case_b probability is 0x00000800 / 0x80000000 = 0.00%
32 ; CHECK: edge entry -> case_c probability is 0x00000800 / 0x80000000 = 0.00%
33 ; CHECK: edge entry -> case_d probability is 0x00000800 / 0x80000000 = 0.00%
45 call void @abort() noreturn
52 define i32 @test3(i32 %a, i32 %b) {
53 ; CHECK: Printing analysis {{.*}} for function 'test3'
54 ; Make sure we unify across multiple conditional branches.
56 %cond1 = icmp eq i32 %a, 42
57 br i1 %cond1, label %exit, label %dom
58 ; CHECK: edge entry -> exit probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
59 ; CHECK: edge entry -> dom probability is 0x00000800 / 0x80000000 = 0.00%
62 %cond2 = icmp ult i32 %a, 42
63 br i1 %cond2, label %idom1, label %idom2
64 ; CHECK: edge dom -> idom1 probability is 0x40000000 / 0x80000000 = 50.00%
65 ; CHECK: edge dom -> idom2 probability is 0x40000000 / 0x80000000 = 50.00%
74 call void @abort() noreturn
81 @_ZTIi = external global i8*
83 ; CHECK-LABEL: throwSmallException
84 ; CHECK-NOT: invoke i32 @smallFunction
85 define i32 @throwSmallException(i32 %idx, i32 %limit) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
87 %cmp = icmp sge i32 %idx, %limit
88 br i1 %cmp, label %if.then, label %if.end
89 ; CHECK: edge entry -> if.then probability is 0x00000800 / 0x80000000 = 0.00%
90 ; CHECK: edge entry -> if.end probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
92 if.then: ; preds = %entry
93 %exception = call i8* @__cxa_allocate_exception(i64 1) #0
94 invoke i32 @smallFunction(i32 %idx)
95 to label %invoke.cont unwind label %lpad
96 ; CHECK: edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
97 ; CHECK: edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
99 invoke.cont: ; preds = %if.then
100 call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #1
103 lpad: ; preds = %if.then
104 %ll = landingpad { i8*, i32 }
108 if.end: ; preds = %entry
113 define i32 @smallFunction(i32 %a) {
115 %r = load volatile i32, i32* @a
119 attributes #0 = { nounwind }
120 attributes #1 = { noreturn }
122 declare i8* @__cxa_allocate_exception(i64)
123 declare i32 @__gxx_personality_v0(...)
124 declare void @__cxa_throw(i8*, i8*, i8*)