1 ; RUN: opt -insert-edge-profiling -o %t1 < %s
2 ; RUN: rm -f %t1.prof_data
3 ; RUN: lli %defaultjit -load %llvmshlibdir/libprofile_rt%shlibext %t1 \
4 ; RUN: -llvmprof-output %t1.prof_data
5 ; RUN: opt -profile-file %t1.prof_data -profile-metadata-loader -S -o - < %s \
7 ; RUN: rm -f %t1.prof_data
9 ; FIXME: profile_rt.dll could be built on win32.
10 ; REQUIRES: loadable_module
12 ;; func_switch - Test branch probabilities for a switch instruction with an
13 ;; even chance of taking each case (or no case).
14 define i32 @func_switch(i32 %N) nounwind uwtable {
16 %retval = alloca i32, align 4
17 %N.addr = alloca i32, align 4
18 store i32 %N, i32* %N.addr, align 4
19 %0 = load i32* %N.addr, align 4
21 switch i32 %rem, label %sw.epilog [
29 store i32 5, i32* %retval
33 store i32 6, i32* %retval
37 store i32 7, i32* %retval
41 store i32 8, i32* %retval
45 %1 = load i32* %retval
49 ;; func_switch_switch - Test branch probabilities in a switch-instruction that
50 ;; leads to further switch instructions. The first-tier switch occludes some
51 ;; possibilities in the second-tier switches, leading to some branches having a
53 define i32 @func_switch_switch(i32 %N) nounwind uwtable {
55 %retval = alloca i32, align 4
56 %N.addr = alloca i32, align 4
57 store i32 %N, i32* %N.addr, align 4
58 %0 = load i32* %N.addr, align 4
60 switch i32 %rem, label %sw.default11 [
67 %1 = load i32* %N.addr, align 4
68 %rem1 = srem i32 %1, 4
69 switch i32 %rem1, label %sw.default [
77 store i32 5, i32* %retval
81 store i32 6, i32* %retval
85 store i32 7, i32* %retval
89 store i32 8, i32* %retval
93 %2 = load i32* %N.addr, align 4
94 %rem6 = srem i32 %2, 4
95 switch i32 %rem6, label %sw.default10 [
103 store i32 9, i32* %retval
107 store i32 10, i32* %retval
111 store i32 11, i32* %retval
115 store i32 12, i32* %retval
119 store i32 13, i32* %retval
123 %3 = load i32* %retval
127 define i32 @main(i32 %argc, i8** %argv) nounwind uwtable {
129 %retval = alloca i32, align 4
130 %argc.addr = alloca i32, align 4
131 %argv.addr = alloca i8**, align 8
132 %loop = alloca i32, align 4
133 store i32 0, i32* %retval
134 store i32 0, i32* %loop, align 4
138 %0 = load i32* %loop, align 4
139 %cmp = icmp slt i32 %0, 4000
140 br i1 %cmp, label %for.body, label %for.end
141 ; CHECK: br i1 %cmp, label %for.body, label %for.end, !prof !4
144 %1 = load i32* %loop, align 4
145 %call = call i32 @func_switch(i32 %1)
146 %2 = load i32* %loop, align 4
147 %call1 = call i32 @func_switch_switch(i32 %2)
151 %3 = load i32* %loop, align 4
152 %inc = add nsw i32 %3, 1
153 store i32 %inc, i32* %loop, align 4
160 ; CHECK: !0 = metadata !{metadata !"branch_weights", i32 1000, i32 1000, i32 1000, i32 1000}
161 ; CHECK: !1 = metadata !{metadata !"branch_weights", i32 0, i32 2000, i32 2000}
162 ; CHECK: !2 = metadata !{metadata !"branch_weights", i32 0, i32 1000, i32 0, i32 1000}
163 ; CHECK: !3 = metadata !{metadata !"branch_weights", i32 1000, i32 0, i32 1000, i32 0}
164 ; CHECK: !4 = metadata !{metadata !"branch_weights", i32 4000, i32 1}