Chandler Carruth | 343fad4 | 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) { |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 4 | ; CHECK-LABEL: Printing analysis {{.*}} for function 'test1': |
| 5 | ; CHECK-NEXT: block-frequency-info: test1 |
| 6 | ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] |
Chandler Carruth | 343fad4 | 2011-10-19 10:12:41 +0000 | [diff] [blame] | 7 | entry: |
| 8 | br label %body |
| 9 | |
| 10 | ; Loop backedges are weighted and thus their bodies have a greater frequency. |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 11 | ; CHECK-NEXT: body: float = 32.0, |
Chandler Carruth | 343fad4 | 2011-10-19 10:12:41 +0000 | [diff] [blame] | 12 | body: |
| 13 | %iv = phi i32 [ 0, %entry ], [ %next, %body ] |
| 14 | %base = phi i32 [ 0, %entry ], [ %sum, %body ] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame^] | 15 | %arrayidx = getelementptr inbounds i32, i32* %a, i32 %iv |
Chandler Carruth | 343fad4 | 2011-10-19 10:12:41 +0000 | [diff] [blame] | 16 | %0 = load i32* %arrayidx |
| 17 | %sum = add nsw i32 %0, %base |
| 18 | %next = add i32 %iv, 1 |
| 19 | %exitcond = icmp eq i32 %next, %i |
| 20 | br i1 %exitcond, label %exit, label %body |
| 21 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 22 | ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]] |
Chandler Carruth | 343fad4 | 2011-10-19 10:12:41 +0000 | [diff] [blame] | 23 | exit: |
| 24 | ret i32 %sum |
| 25 | } |
Chandler Carruth | d27a7a9 | 2011-10-19 10:30:30 +0000 | [diff] [blame] | 26 | |
| 27 | define i32 @test2(i32 %i, i32 %a, i32 %b) { |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 28 | ; CHECK-LABEL: Printing analysis {{.*}} for function 'test2': |
| 29 | ; CHECK-NEXT: block-frequency-info: test2 |
| 30 | ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] |
Chandler Carruth | d27a7a9 | 2011-10-19 10:30:30 +0000 | [diff] [blame] | 31 | entry: |
| 32 | %cond = icmp ult i32 %i, 42 |
| 33 | br i1 %cond, label %then, label %else, !prof !0 |
| 34 | |
| 35 | ; The 'then' branch is predicted more likely via branch weight metadata. |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 36 | ; CHECK-NEXT: then: float = 0.9411{{[0-9]*}}, |
Chandler Carruth | d27a7a9 | 2011-10-19 10:30:30 +0000 | [diff] [blame] | 37 | then: |
| 38 | br label %exit |
| 39 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 40 | ; CHECK-NEXT: else: float = 0.05882{{[0-9]*}}, |
Chandler Carruth | d27a7a9 | 2011-10-19 10:30:30 +0000 | [diff] [blame] | 41 | else: |
| 42 | br label %exit |
| 43 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 44 | ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]] |
Chandler Carruth | d27a7a9 | 2011-10-19 10:30:30 +0000 | [diff] [blame] | 45 | exit: |
| 46 | %result = phi i32 [ %a, %then ], [ %b, %else ] |
| 47 | ret i32 %result |
| 48 | } |
| 49 | |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 50 | !0 = !{!"branch_weights", i32 64, i32 4} |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 51 | |
| 52 | define i32 @test3(i32 %i, i32 %a, i32 %b, i32 %c, i32 %d, i32 %e) { |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 53 | ; CHECK-LABEL: Printing analysis {{.*}} for function 'test3': |
| 54 | ; CHECK-NEXT: block-frequency-info: test3 |
| 55 | ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 56 | entry: |
| 57 | switch i32 %i, label %case_a [ i32 1, label %case_b |
| 58 | i32 2, label %case_c |
| 59 | i32 3, label %case_d |
| 60 | i32 4, label %case_e ], !prof !1 |
| 61 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 62 | ; CHECK-NEXT: case_a: float = 0.05, |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 63 | case_a: |
| 64 | br label %exit |
| 65 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 66 | ; CHECK-NEXT: case_b: float = 0.05, |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 67 | case_b: |
| 68 | br label %exit |
| 69 | |
| 70 | ; The 'case_c' branch is predicted more likely via branch weight metadata. |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 71 | ; CHECK-NEXT: case_c: float = 0.8, |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 72 | case_c: |
| 73 | br label %exit |
| 74 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 75 | ; CHECK-NEXT: case_d: float = 0.05, |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 76 | case_d: |
| 77 | br label %exit |
| 78 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 79 | ; CHECK-NEXT: case_e: float = 0.05, |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 80 | case_e: |
| 81 | br label %exit |
| 82 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 83 | ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]] |
Chandler Carruth | deac50c | 2011-10-19 10:32:19 +0000 | [diff] [blame] | 84 | exit: |
| 85 | %result = phi i32 [ %a, %case_a ], |
| 86 | [ %b, %case_b ], |
| 87 | [ %c, %case_c ], |
| 88 | [ %d, %case_d ], |
| 89 | [ %e, %case_e ] |
| 90 | ret i32 %result |
| 91 | } |
| 92 | |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 93 | !1 = !{!"branch_weights", i32 4, i32 4, i32 64, i32 4, i32 4} |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 94 | |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 95 | define void @nested_loops(i32 %a) { |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 96 | ; CHECK-LABEL: Printing analysis {{.*}} for function 'nested_loops': |
| 97 | ; CHECK-NEXT: block-frequency-info: nested_loops |
| 98 | ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 99 | entry: |
| 100 | br label %for.cond1.preheader |
| 101 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 102 | ; CHECK-NEXT: for.cond1.preheader: float = 4001.0, |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 103 | for.cond1.preheader: |
| 104 | %x.024 = phi i32 [ 0, %entry ], [ %inc12, %for.inc11 ] |
| 105 | br label %for.cond4.preheader |
| 106 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 107 | ; CHECK-NEXT: for.cond4.preheader: float = 16008001.0, |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 108 | for.cond4.preheader: |
| 109 | %y.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc9, %for.inc8 ] |
| 110 | %add = add i32 %y.023, %x.024 |
| 111 | br label %for.body6 |
| 112 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 113 | ; CHECK-NEXT: for.body6: float = 64048012001.0, |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 114 | for.body6: |
| 115 | %z.022 = phi i32 [ 0, %for.cond4.preheader ], [ %inc, %for.body6 ] |
| 116 | %add7 = add i32 %add, %z.022 |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 117 | tail call void @g(i32 %add7) |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 118 | %inc = add i32 %z.022, 1 |
| 119 | %cmp5 = icmp ugt i32 %inc, %a |
| 120 | br i1 %cmp5, label %for.inc8, label %for.body6, !prof !2 |
| 121 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 122 | ; CHECK-NEXT: for.inc8: float = 16008001.0, |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 123 | for.inc8: |
| 124 | %inc9 = add i32 %y.023, 1 |
| 125 | %cmp2 = icmp ugt i32 %inc9, %a |
| 126 | br i1 %cmp2, label %for.inc11, label %for.cond4.preheader, !prof !2 |
| 127 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 128 | ; CHECK-NEXT: for.inc11: float = 4001.0, |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 129 | for.inc11: |
| 130 | %inc12 = add i32 %x.024, 1 |
| 131 | %cmp = icmp ugt i32 %inc12, %a |
| 132 | br i1 %cmp, label %for.end13, label %for.cond1.preheader, !prof !2 |
| 133 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 134 | ; CHECK-NEXT: for.end13: float = 1.0, int = [[ENTRY]] |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 135 | for.end13: |
| 136 | ret void |
| 137 | } |
| 138 | |
Duncan P. N. Exon Smith | 10be9a8 | 2014-04-21 17:57:07 +0000 | [diff] [blame] | 139 | declare void @g(i32) |
Jakob Stoklund Olesen | 0b07510 | 2013-06-28 22:40:43 +0000 | [diff] [blame] | 140 | |
Duncan P. N. Exon Smith | be7ea19 | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 141 | !2 = !{!"branch_weights", i32 1, i32 4000} |