Chandler Carruth | 6aa5c26 | 2011-10-19 10:12:41 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -analyze -block-freq | FileCheck %s |
| 2 | |
| 3 | define i32 @test1(i32 %i, i32* %a) { |
| 4 | ; CHECK: Printing analysis {{.*}} for function 'test1' |
| 5 | ; CHECK: entry = 1024 |
| 6 | entry: |
| 7 | br label %body |
| 8 | |
| 9 | ; Loop backedges are weighted and thus their bodies have a greater frequency. |
| 10 | ; CHECK: body = 31744 |
| 11 | body: |
| 12 | %iv = phi i32 [ 0, %entry ], [ %next, %body ] |
| 13 | %base = phi i32 [ 0, %entry ], [ %sum, %body ] |
| 14 | %arrayidx = getelementptr inbounds i32* %a, i32 %iv |
| 15 | %0 = load i32* %arrayidx |
| 16 | %sum = add nsw i32 %0, %base |
| 17 | %next = add i32 %iv, 1 |
| 18 | %exitcond = icmp eq i32 %next, %i |
| 19 | br i1 %exitcond, label %exit, label %body |
| 20 | |
| 21 | ; CHECK: exit = 1024 |
| 22 | exit: |
| 23 | ret i32 %sum |
| 24 | } |
Chandler Carruth | 99d01c5 | 2011-10-19 10:30:30 +0000 | [diff] [blame^] | 25 | |
| 26 | define i32 @test2(i32 %i, i32 %a, i32 %b) { |
| 27 | ; CHECK: Printing analysis {{.*}} for function 'test2' |
| 28 | ; CHECK: entry = 1024 |
| 29 | entry: |
| 30 | %cond = icmp ult i32 %i, 42 |
| 31 | br i1 %cond, label %then, label %else, !prof !0 |
| 32 | |
| 33 | ; The 'then' branch is predicted more likely via branch weight metadata. |
| 34 | ; CHECK: then = 963 |
| 35 | then: |
| 36 | br label %exit |
| 37 | |
| 38 | ; CHECK: else = 60 |
| 39 | else: |
| 40 | br label %exit |
| 41 | |
| 42 | ; FIXME: It may be a bug that we don't sum back to 1024. |
| 43 | ; CHECK: exit = 1023 |
| 44 | exit: |
| 45 | %result = phi i32 [ %a, %then ], [ %b, %else ] |
| 46 | ret i32 %result |
| 47 | } |
| 48 | |
| 49 | !0 = metadata !{metadata !"branch_weights", i32 64, i32 4} |