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