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 \ 6 ; RUN: | FileCheck %s 7 ; RUN: rm -f %t1.prof_data 8 9 ; FIXME: profile_rt.dll could be built on win32. 10 ; REQUIRES: loadable_module 11 12 ;; func_mod - Branch taken 6 times in 7. 13 define i32 @func_mod(i32 %N) nounwind uwtable { 14 entry: 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 19 %rem = srem i32 %0, 7 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 23 24 if.then: 25 store i32 1, i32* %retval 26 br label %return 27 28 if.else: 29 store i32 0, i32* %retval 30 br label %return 31 32 return: 33 %1 = load i32* %retval 34 ret i32 %1 35 } 36 37 ;; func_const_true - conditional branch which 100% taken probability. 38 define i32 @func_const_true(i32 %N) nounwind uwtable { 39 entry: 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 47 48 if.then: 49 store i32 1, i32* %retval 50 br label %return 51 52 if.end: 53 store i32 0, i32* %retval 54 br label %return 55 56 return: 57 %1 = load i32* %retval 58 ret i32 %1 59 } 60 61 ;; func_const_true - conditional branch which 100% not-taken probability. 62 define i32 @func_const_false(i32 %N) nounwind uwtable { 63 entry: 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 71 72 if.then: 73 store i32 1, i32* %retval 74 br label %return 75 76 if.end: 77 store i32 0, i32* %retval 78 br label %return 79 80 return: 81 %1 = load i32* %retval 82 ret i32 %1 83 } 84 85 define i32 @main(i32 %argc, i8** %argv) nounwind uwtable { 86 entry: 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 93 br label %for.cond 94 95 for.cond: 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 100 101 for.body: 102 %1 = load i32* %loop, align 4 103 %call = call i32 @func_mod(i32 %1) 104 br label %for.inc 105 106 for.inc: 107 %2 = load i32* %loop, align 4 108 %inc = add nsw i32 %2, 1 109 store i32 %inc, i32* %loop, align 4 110 br label %for.cond 111 112 for.end: 113 %call1 = call i32 @func_const_true(i32 1) 114 %call2 = call i32 @func_const_false(i32 0) 115 ret i32 0 116 } 117 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} 122 ; CHECK-NOT: !4 123