1 ; RUN: opt < %s -analyze -block-freq | FileCheck %s 2 3 ; CHECK-LABEL: Printing analysis {{.*}} for function 'double_exit': 4 ; CHECK-NEXT: block-frequency-info: double_exit 5 define i32 @double_exit(i32 %N) { 6 ; Mass = 1 7 ; Frequency = 1 8 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] 9 entry: 10 br label %outer 11 12 ; Mass = 1 13 ; Backedge mass = 1/3, exit mass = 2/3 14 ; Loop scale = 3/2 15 ; Pseudo-edges = exit 16 ; Pseudo-mass = 1 17 ; Frequency = 1*3/2*1 = 3/2 18 ; CHECK-NEXT: outer: float = 1.5, 19 outer: 20 %I.0 = phi i32 [ 0, %entry ], [ %inc6, %outer.inc ] 21 %Return.0 = phi i32 [ 0, %entry ], [ %Return.1, %outer.inc ] 22 %cmp = icmp slt i32 %I.0, %N 23 br i1 %cmp, label %inner, label %exit, !prof !2 ; 2:1 24 25 ; Mass = 1 26 ; Backedge mass = 3/5, exit mass = 2/5 27 ; Loop scale = 5/2 28 ; Pseudo-edges = outer.inc @ 1/5, exit @ 1/5 29 ; Pseudo-mass = 2/3 30 ; Frequency = 3/2*1*5/2*2/3 = 5/2 31 ; CHECK-NEXT: inner: float = 2.5, 32 inner: 33 %Return.1 = phi i32 [ %Return.0, %outer ], [ %call4, %inner.inc ] 34 %J.0 = phi i32 [ %I.0, %outer ], [ %inc, %inner.inc ] 35 %cmp2 = icmp slt i32 %J.0, %N 36 br i1 %cmp2, label %inner.body, label %outer.inc, !prof !1 ; 4:1 37 38 ; Mass = 4/5 39 ; Frequency = 5/2*4/5 = 2 40 ; CHECK-NEXT: inner.body: float = 2.0, 41 inner.body: 42 %call = call i32 @c2(i32 %I.0, i32 %J.0) 43 %tobool = icmp ne i32 %call, 0 44 br i1 %tobool, label %exit, label %inner.inc, !prof !0 ; 3:1 45 46 ; Mass = 3/5 47 ; Frequency = 5/2*3/5 = 3/2 48 ; CHECK-NEXT: inner.inc: float = 1.5, 49 inner.inc: 50 %call4 = call i32 @logic2(i32 %Return.1, i32 %I.0, i32 %J.0) 51 %inc = add nsw i32 %J.0, 1 52 br label %inner 53 54 ; Mass = 1/3 55 ; Frequency = 3/2*1/3 = 1/2 56 ; CHECK-NEXT: outer.inc: float = 0.5, 57 outer.inc: 58 %inc6 = add nsw i32 %I.0, 1 59 br label %outer 60 61 ; Mass = 1 62 ; Frequency = 1 63 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]] 64 exit: 65 %Return.2 = phi i32 [ %Return.1, %inner.body ], [ %Return.0, %outer ] 66 ret i32 %Return.2 67 } 68 69 !0 = !{!"branch_weights", i32 1, i32 3} 70 !1 = !{!"branch_weights", i32 4, i32 1} 71 !2 = !{!"branch_weights", i32 2, i32 1} 72 73 declare i32 @c2(i32, i32) 74 declare i32 @logic2(i32, i32, i32) 75 76 ; CHECK-LABEL: Printing analysis {{.*}} for function 'double_exit_in_loop': 77 ; CHECK-NEXT: block-frequency-info: double_exit_in_loop 78 define i32 @double_exit_in_loop(i32 %N) { 79 ; Mass = 1 80 ; Frequency = 1 81 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] 82 entry: 83 br label %outer 84 85 ; Mass = 1 86 ; Backedge mass = 1/2, exit mass = 1/2 87 ; Loop scale = 2 88 ; Pseudo-edges = exit 89 ; Pseudo-mass = 1 90 ; Frequency = 1*2*1 = 2 91 ; CHECK-NEXT: outer: float = 2.0, 92 outer: 93 %I.0 = phi i32 [ 0, %entry ], [ %inc12, %outer.inc ] 94 %Return.0 = phi i32 [ 0, %entry ], [ %Return.3, %outer.inc ] 95 %cmp = icmp slt i32 %I.0, %N 96 br i1 %cmp, label %middle, label %exit, !prof !3 ; 1:1 97 98 ; Mass = 1 99 ; Backedge mass = 1/3, exit mass = 2/3 100 ; Loop scale = 3/2 101 ; Pseudo-edges = outer.inc 102 ; Pseudo-mass = 1/2 103 ; Frequency = 2*1*3/2*1/2 = 3/2 104 ; CHECK-NEXT: middle: float = 1.5, 105 middle: 106 %J.0 = phi i32 [ %I.0, %outer ], [ %inc9, %middle.inc ] 107 %Return.1 = phi i32 [ %Return.0, %outer ], [ %Return.2, %middle.inc ] 108 %cmp2 = icmp slt i32 %J.0, %N 109 br i1 %cmp2, label %inner, label %outer.inc, !prof !2 ; 2:1 110 111 ; Mass = 1 112 ; Backedge mass = 3/5, exit mass = 2/5 113 ; Loop scale = 5/2 114 ; Pseudo-edges = middle.inc @ 1/5, outer.inc @ 1/5 115 ; Pseudo-mass = 2/3 116 ; Frequency = 3/2*1*5/2*2/3 = 5/2 117 ; CHECK-NEXT: inner: float = 2.5, 118 inner: 119 %Return.2 = phi i32 [ %Return.1, %middle ], [ %call7, %inner.inc ] 120 %K.0 = phi i32 [ %J.0, %middle ], [ %inc, %inner.inc ] 121 %cmp5 = icmp slt i32 %K.0, %N 122 br i1 %cmp5, label %inner.body, label %middle.inc, !prof !1 ; 4:1 123 124 ; Mass = 4/5 125 ; Frequency = 5/2*4/5 = 2 126 ; CHECK-NEXT: inner.body: float = 2.0, 127 inner.body: 128 %call = call i32 @c3(i32 %I.0, i32 %J.0, i32 %K.0) 129 %tobool = icmp ne i32 %call, 0 130 br i1 %tobool, label %outer.inc, label %inner.inc, !prof !0 ; 3:1 131 132 ; Mass = 3/5 133 ; Frequency = 5/2*3/5 = 3/2 134 ; CHECK-NEXT: inner.inc: float = 1.5, 135 inner.inc: 136 %call7 = call i32 @logic3(i32 %Return.2, i32 %I.0, i32 %J.0, i32 %K.0) 137 %inc = add nsw i32 %K.0, 1 138 br label %inner 139 140 ; Mass = 1/3 141 ; Frequency = 3/2*1/3 = 1/2 142 ; CHECK-NEXT: middle.inc: float = 0.5, 143 middle.inc: 144 %inc9 = add nsw i32 %J.0, 1 145 br label %middle 146 147 ; Mass = 1/2 148 ; Frequency = 2*1/2 = 1 149 ; CHECK-NEXT: outer.inc: float = 1.0, 150 outer.inc: 151 %Return.3 = phi i32 [ %Return.2, %inner.body ], [ %Return.1, %middle ] 152 %inc12 = add nsw i32 %I.0, 1 153 br label %outer 154 155 ; Mass = 1 156 ; Frequency = 1 157 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]] 158 exit: 159 ret i32 %Return.0 160 } 161 162 !3 = !{!"branch_weights", i32 1, i32 1} 163 164 declare i32 @c3(i32, i32, i32) 165 declare i32 @logic3(i32, i32, i32, i32) 166