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_mod - Branch taken 6 times in 7.
13 define i32 @func_mod(i32 %N) nounwind uwtable {
15 %retval = alloca i32, align 4
16 %N.addr = alloca i32, align 4
17 store i32 %N, i32* %N.addr, align 4
18 %0 = load i32* %N.addr, align 4
20 %tobool = icmp ne i32 %rem, 0
21 br i1 %tobool, label %if.then, label %if.else
22 ; CHECK: br i1 %tobool, label %if.then, label %if.else, !prof !0
25 store i32 1, i32* %retval
29 store i32 0, i32* %retval
33 %1 = load i32* %retval
37 ;; func_const_true - conditional branch which 100% taken probability.
38 define i32 @func_const_true(i32 %N) nounwind uwtable {
40 %retval = alloca i32, align 4
41 %N.addr = alloca i32, align 4
42 store i32 %N, i32* %N.addr, align 4
43 %0 = load i32* %N.addr, align 4
44 %cmp = icmp eq i32 %0, 1
45 br i1 %cmp, label %if.then, label %if.end
46 ; CHECK: br i1 %cmp, label %if.then, label %if.end, !prof !1
49 store i32 1, i32* %retval
53 store i32 0, i32* %retval
57 %1 = load i32* %retval
61 ;; func_const_true - conditional branch which 100% not-taken probability.
62 define i32 @func_const_false(i32 %N) nounwind uwtable {
64 %retval = alloca i32, align 4
65 %N.addr = alloca i32, align 4
66 store i32 %N, i32* %N.addr, align 4
67 %0 = load i32* %N.addr, align 4
68 %cmp = icmp eq i32 %0, 1
69 br i1 %cmp, label %if.then, label %if.end
70 ; CHECK: br i1 %cmp, label %if.then, label %if.end, !prof !2
73 store i32 1, i32* %retval
77 store i32 0, i32* %retval
81 %1 = load i32* %retval
85 define i32 @main(i32 %argc, i8** %argv) nounwind uwtable {
87 %retval = alloca i32, align 4
88 %argc.addr = alloca i32, align 4
89 %argv.addr = alloca i8**, align 8
90 %loop = alloca i32, align 4
91 store i32 0, i32* %retval
92 store i32 0, i32* %loop, align 4
96 %0 = load i32* %loop, align 4
97 %cmp = icmp slt i32 %0, 7000
98 br i1 %cmp, label %for.body, label %for.end
99 ; CHECK: br i1 %cmp, label %for.body, label %for.end, !prof !3
102 %1 = load i32* %loop, align 4
103 %call = call i32 @func_mod(i32 %1)
107 %2 = load i32* %loop, align 4
108 %inc = add nsw i32 %2, 1
109 store i32 %inc, i32* %loop, align 4
113 %call1 = call i32 @func_const_true(i32 1)
114 %call2 = call i32 @func_const_false(i32 0)
118 ; CHECK: !0 = metadata !{metadata !"branch_weights", i32 6000, i32 1000}
119 ; CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 0}
120 ; CHECK: !2 = metadata !{metadata !"branch_weights", i32 0, i32 1}
121 ; CHECK: !3 = metadata !{metadata !"branch_weights", i32 7000, i32 1}