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