Manman Ren | abbb01ab | 2012-08-28 22:21:25 +0000 | [diff] [blame^] | 1 | ; RUN: opt -insert-edge-profiling -o %t1 < %s |
| 2 | ; RUN: rm -f %t1.prof_data |
| 3 | ; RUN: lli -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 | ;; func_for - Test branch probabilities for a vanilla for loop. |
| 10 | define i32 @func_for(i32 %N) nounwind uwtable { |
| 11 | entry: |
| 12 | %N.addr = alloca i32, align 4 |
| 13 | %ret = alloca i32, align 4 |
| 14 | %loop = alloca i32, align 4 |
| 15 | store i32 %N, i32* %N.addr, align 4 |
| 16 | store i32 0, i32* %ret, align 4 |
| 17 | store i32 0, i32* %loop, align 4 |
| 18 | br label %for.cond |
| 19 | |
| 20 | for.cond: |
| 21 | %0 = load i32* %loop, align 4 |
| 22 | %1 = load i32* %N.addr, align 4 |
| 23 | %cmp = icmp slt i32 %0, %1 |
| 24 | br i1 %cmp, label %for.body, label %for.end |
| 25 | ; CHECK: br i1 %cmp, label %for.body, label %for.end, !prof !0 |
| 26 | |
| 27 | for.body: |
| 28 | %2 = load i32* %N.addr, align 4 |
| 29 | %3 = load i32* %ret, align 4 |
| 30 | %add = add nsw i32 %3, %2 |
| 31 | store i32 %add, i32* %ret, align 4 |
| 32 | br label %for.inc |
| 33 | |
| 34 | for.inc: |
| 35 | %4 = load i32* %loop, align 4 |
| 36 | %inc = add nsw i32 %4, 1 |
| 37 | store i32 %inc, i32* %loop, align 4 |
| 38 | br label %for.cond |
| 39 | |
| 40 | for.end: |
| 41 | %5 = load i32* %ret, align 4 |
| 42 | ret i32 %5 |
| 43 | } |
| 44 | |
| 45 | ;; func_for_odd - Test branch probabilities for a for loop with a continue and |
| 46 | ;; a break. |
| 47 | define i32 @func_for_odd(i32 %N) nounwind uwtable { |
| 48 | entry: |
| 49 | %N.addr = alloca i32, align 4 |
| 50 | %ret = alloca i32, align 4 |
| 51 | %loop = alloca i32, align 4 |
| 52 | store i32 %N, i32* %N.addr, align 4 |
| 53 | store i32 0, i32* %ret, align 4 |
| 54 | store i32 0, i32* %loop, align 4 |
| 55 | br label %for.cond |
| 56 | |
| 57 | for.cond: |
| 58 | %0 = load i32* %loop, align 4 |
| 59 | %1 = load i32* %N.addr, align 4 |
| 60 | %cmp = icmp slt i32 %0, %1 |
| 61 | br i1 %cmp, label %for.body, label %for.end |
| 62 | ; CHECK: br i1 %cmp, label %for.body, label %for.end, !prof !1 |
| 63 | |
| 64 | for.body: |
| 65 | %2 = load i32* %loop, align 4 |
| 66 | %rem = srem i32 %2, 10 |
| 67 | %tobool = icmp ne i32 %rem, 0 |
| 68 | br i1 %tobool, label %if.then, label %if.end |
| 69 | ; CHECK: br i1 %tobool, label %if.then, label %if.end, !prof !2 |
| 70 | |
| 71 | if.then: |
| 72 | br label %for.inc |
| 73 | |
| 74 | if.end: |
| 75 | %3 = load i32* %loop, align 4 |
| 76 | %cmp1 = icmp eq i32 %3, 500 |
| 77 | br i1 %cmp1, label %if.then2, label %if.end3 |
| 78 | ; CHECK: br i1 %cmp1, label %if.then2, label %if.end3, !prof !3 |
| 79 | |
| 80 | if.then2: |
| 81 | br label %for.end |
| 82 | |
| 83 | if.end3: |
| 84 | %4 = load i32* %N.addr, align 4 |
| 85 | %5 = load i32* %ret, align 4 |
| 86 | %add = add nsw i32 %5, %4 |
| 87 | store i32 %add, i32* %ret, align 4 |
| 88 | br label %for.inc |
| 89 | |
| 90 | for.inc: |
| 91 | %6 = load i32* %loop, align 4 |
| 92 | %inc = add nsw i32 %6, 1 |
| 93 | store i32 %inc, i32* %loop, align 4 |
| 94 | br label %for.cond |
| 95 | |
| 96 | for.end: |
| 97 | %7 = load i32* %ret, align 4 |
| 98 | ret i32 %7 |
| 99 | } |
| 100 | |
| 101 | ;; func_while - Test branch probability in a vanilla while loop. |
| 102 | define i32 @func_while(i32 %N) nounwind uwtable { |
| 103 | entry: |
| 104 | %N.addr = alloca i32, align 4 |
| 105 | %ret = alloca i32, align 4 |
| 106 | %loop = alloca i32, align 4 |
| 107 | store i32 %N, i32* %N.addr, align 4 |
| 108 | store i32 0, i32* %ret, align 4 |
| 109 | store i32 0, i32* %loop, align 4 |
| 110 | br label %while.cond |
| 111 | |
| 112 | while.cond: |
| 113 | %0 = load i32* %loop, align 4 |
| 114 | %1 = load i32* %N.addr, align 4 |
| 115 | %cmp = icmp slt i32 %0, %1 |
| 116 | br i1 %cmp, label %while.body, label %while.end |
| 117 | ; CHECK: br i1 %cmp, label %while.body, label %while.end, !prof !0 |
| 118 | |
| 119 | while.body: |
| 120 | %2 = load i32* %N.addr, align 4 |
| 121 | %3 = load i32* %ret, align 4 |
| 122 | %add = add nsw i32 %3, %2 |
| 123 | store i32 %add, i32* %ret, align 4 |
| 124 | %4 = load i32* %loop, align 4 |
| 125 | %inc = add nsw i32 %4, 1 |
| 126 | store i32 %inc, i32* %loop, align 4 |
| 127 | br label %while.cond |
| 128 | |
| 129 | while.end: |
| 130 | %5 = load i32* %ret, align 4 |
| 131 | ret i32 %5 |
| 132 | } |
| 133 | |
| 134 | ;; func_while - Test branch probability in a vanilla do-while loop. |
| 135 | define i32 @func_do_while(i32 %N) nounwind uwtable { |
| 136 | entry: |
| 137 | %N.addr = alloca i32, align 4 |
| 138 | %ret = alloca i32, align 4 |
| 139 | %loop = alloca i32, align 4 |
| 140 | store i32 %N, i32* %N.addr, align 4 |
| 141 | store i32 0, i32* %ret, align 4 |
| 142 | store i32 0, i32* %loop, align 4 |
| 143 | br label %do.body |
| 144 | |
| 145 | do.body: |
| 146 | %0 = load i32* %N.addr, align 4 |
| 147 | %1 = load i32* %ret, align 4 |
| 148 | %add = add nsw i32 %1, %0 |
| 149 | store i32 %add, i32* %ret, align 4 |
| 150 | %2 = load i32* %loop, align 4 |
| 151 | %inc = add nsw i32 %2, 1 |
| 152 | store i32 %inc, i32* %loop, align 4 |
| 153 | br label %do.cond |
| 154 | |
| 155 | do.cond: |
| 156 | %3 = load i32* %loop, align 4 |
| 157 | %4 = load i32* %N.addr, align 4 |
| 158 | %cmp = icmp slt i32 %3, %4 |
| 159 | br i1 %cmp, label %do.body, label %do.end |
| 160 | ; CHECK: br i1 %cmp, label %do.body, label %do.end, !prof !4 |
| 161 | |
| 162 | do.end: |
| 163 | %5 = load i32* %ret, align 4 |
| 164 | ret i32 %5 |
| 165 | } |
| 166 | |
| 167 | define i32 @main(i32 %argc, i8** %argv) nounwind uwtable { |
| 168 | entry: |
| 169 | %retval = alloca i32, align 4 |
| 170 | %argc.addr = alloca i32, align 4 |
| 171 | %argv.addr = alloca i8**, align 8 |
| 172 | store i32 0, i32* %retval |
| 173 | %call = call i32 @func_for(i32 1000) |
| 174 | %call1 = call i32 @func_for_odd(i32 1000) |
| 175 | %call2 = call i32 @func_while(i32 1000) |
| 176 | %call3 = call i32 @func_do_while(i32 1000) |
| 177 | ret i32 0 |
| 178 | } |
| 179 | |
| 180 | !0 = metadata !{metadata !"branch_weights", i32 1000, i32 1} |
| 181 | !1 = metadata !{metadata !"branch_weights", i32 501, i32 0} |
| 182 | !2 = metadata !{metadata !"branch_weights", i32 450, i32 51} |
| 183 | !3 = metadata !{metadata !"branch_weights", i32 1, i32 50} |
| 184 | !4 = metadata !{metadata !"branch_weights", i32 999, i32 1} |
| 185 | ; CHECK-NOT: !5 |