]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/BranchProbabilityInfo/noreturn.ll
Vendor import of llvm trunk r303571:
[FreeBSD/FreeBSD.git] / test / Analysis / BranchProbabilityInfo / noreturn.ll
1 ; Test the static branch probability heuristics for no-return functions.
2 ; RUN: opt < %s -analyze -branch-prob | FileCheck %s
3 ; RUN: opt < %s -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
4
5 declare void @abort() noreturn
6
7 define i32 @test1(i32 %a, i32 %b) {
8 ; CHECK: Printing analysis {{.*}} for function 'test1'
9 entry:
10   %cond = icmp eq i32 %a, 42
11   br i1 %cond, label %exit, label %abort
12 ; CHECK: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
13 ; CHECK: edge entry -> abort probability is 0x00000001 / 0x80000000 = 0.00%
14
15 abort:
16   call void @abort() noreturn
17   unreachable
18
19 exit:
20   ret i32 %b
21 }
22
23 define i32 @test2(i32 %a, i32 %b) {
24 ; CHECK: Printing analysis {{.*}} for function 'test2'
25 entry:
26   switch i32 %a, label %exit [i32 1, label %case_a
27                               i32 2, label %case_b
28                               i32 3, label %case_c
29                               i32 4, label %case_d]
30 ; CHECK: edge entry -> exit probability is 0x7ffffffc / 0x80000000 = 100.00% [HOT edge]
31 ; CHECK: edge entry -> case_a probability is 0x00000001 / 0x80000000 = 0.00%
32 ; CHECK: edge entry -> case_b probability is 0x00000001 / 0x80000000 = 0.00%
33 ; CHECK: edge entry -> case_c probability is 0x00000001 / 0x80000000 = 0.00%
34 ; CHECK: edge entry -> case_d probability is 0x00000001 / 0x80000000 = 0.00%
35
36 case_a:
37   br label %case_b
38
39 case_b:
40   br label %case_c
41
42 case_c:
43   br label %case_d
44
45 case_d:
46   call void @abort() noreturn
47   unreachable
48
49 exit:
50   ret i32 %b
51 }
52
53 define i32 @test3(i32 %a, i32 %b) {
54 ; CHECK: Printing analysis {{.*}} for function 'test3'
55 ; Make sure we unify across multiple conditional branches.
56 entry:
57   %cond1 = icmp eq i32 %a, 42
58   br i1 %cond1, label %exit, label %dom
59 ; CHECK: edge entry -> exit probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
60 ; CHECK: edge entry -> dom probability is 0x00000001 / 0x80000000 = 0.00%
61
62 dom:
63   %cond2 = icmp ult i32 %a, 42
64   br i1 %cond2, label %idom1, label %idom2
65 ; CHECK: edge dom -> idom1 probability is 0x40000000 / 0x80000000 = 50.00%
66 ; CHECK: edge dom -> idom2 probability is 0x40000000 / 0x80000000 = 50.00%
67
68 idom1:
69   br label %abort
70
71 idom2:
72   br label %abort
73
74 abort:
75   call void @abort() noreturn
76   unreachable
77
78 exit:
79   ret i32 %b
80 }
81
82 @_ZTIi = external global i8*
83
84 ; CHECK-LABEL: throwSmallException
85 ; CHECK-NOT: invoke i32 @smallFunction
86 define i32 @throwSmallException(i32 %idx, i32 %limit) #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
87 entry:
88   %cmp = icmp sge i32 %idx, %limit
89   br i1 %cmp, label %if.then, label %if.end
90 ; CHECK: edge entry -> if.then probability is 0x00000001 / 0x80000000 = 0.00%
91 ; CHECK: edge entry -> if.end probability is 0x7fffffff / 0x80000000 = 100.00% [HOT edge]
92
93 if.then:                                          ; preds = %entry
94   %exception = call i8* @__cxa_allocate_exception(i64 1) #0
95   invoke i32 @smallFunction(i32 %idx)
96           to label %invoke.cont unwind label %lpad
97 ; CHECK: edge if.then -> invoke.cont probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
98 ; CHECK: edge if.then -> lpad probability is 0x00000800 / 0x80000000 = 0.00%
99
100 invoke.cont:                                      ; preds = %if.then
101   call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi  to i8*), i8* null) #1
102   unreachable
103
104 lpad:                                             ; preds = %if.then
105   %ll = landingpad { i8*, i32 }
106           cleanup
107   ret i32 %idx
108
109 if.end:                                           ; preds = %entry
110   ret i32 %idx
111 }
112
113 @a = global i32 4
114 define i32 @smallFunction(i32 %a) {
115 entry:
116   %r = load volatile i32, i32* @a
117   ret i32 %r
118 }
119
120 attributes #0 = { nounwind }
121 attributes #1 = { noreturn }
122
123 declare i8* @__cxa_allocate_exception(i64)
124 declare i32 @__gxx_personality_v0(...)
125 declare void @__cxa_throw(i8*, i8*, i8*)