1; RUN: opt < %s -analyze -block-freq -enable-new-pm=0 | FileCheck %s 2; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s 3 4; Function Attrs: noinline norecurse nounwind readnone uwtable 5define i32 @_Z11irreducibleii(i32 %iter_outer, i32 %iter_inner) local_unnamed_addr !prof !27 { 6entry: 7 %cmp24 = icmp sgt i32 %iter_outer, 0 8 br i1 %cmp24, label %for.body, label %entry.for.cond.cleanup_crit_edge, !prof !28 9 10entry.for.cond.cleanup_crit_edge: ; preds = %entry 11 br label %for.cond.cleanup 12 13for.cond.cleanup: ; preds = %for.end, %entry.for.cond.cleanup_crit_edge 14 %sum.0.lcssa = phi i32 [ 0, %entry.for.cond.cleanup_crit_edge ], [ %sum.1, %for.end ] 15 ret i32 %sum.0.lcssa 16 17for.body: ; preds = %for.end, %entry 18 %k.026 = phi i32 [ %inc12, %for.end ], [ 0, %entry ] 19 %sum.025 = phi i32 [ %sum.1, %for.end ], [ 0, %entry ] 20 %rem23 = and i32 %k.026, 1 21 %cmp1 = icmp eq i32 %rem23, 0 22 br i1 %cmp1, label %entry8, label %for.cond2, !prof !29 23 24for.cond2: ; preds = %if.end9, %for.body 25 %sum.1 = phi i32 [ %add10, %if.end9 ], [ %sum.025, %for.body ] 26 %i.0 = phi i32 [ %inc, %if.end9 ], [ 0, %for.body ] 27 %cmp3 = icmp slt i32 %i.0, %iter_inner 28 br i1 %cmp3, label %for.body4, label %for.end, !prof !30, !irr_loop !31 29 30for.body4: ; preds = %for.cond2 31 %rem5 = srem i32 %k.026, 3 32 %cmp6 = icmp eq i32 %rem5, 0 33 br i1 %cmp6, label %entry8, label %if.end9, !prof !32 34 35entry8: ; preds = %for.body4, %for.body 36 %sum.2 = phi i32 [ %sum.025, %for.body ], [ %sum.1, %for.body4 ] 37 %i.1 = phi i32 [ 0, %for.body ], [ %i.0, %for.body4 ] 38 %add = add nsw i32 %sum.2, 4 39 br label %if.end9, !irr_loop !33 40 41if.end9: ; preds = %entry8, %for.body4 42 %sum.3 = phi i32 [ %add, %entry8 ], [ %sum.1, %for.body4 ] 43 %i.2 = phi i32 [ %i.1, %entry8 ], [ %i.0, %for.body4 ] 44 %add10 = add nsw i32 %sum.3, 1 45 %inc = add nsw i32 %i.2, 1 46 br label %for.cond2, !irr_loop !34 47 48for.end: ; preds = %for.cond2 49 %inc12 = add nuw nsw i32 %k.026, 1 50 %exitcond = icmp eq i32 %inc12, %iter_outer 51 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !prof !35 52} 53 54!27 = !{!"function_entry_count", i64 1} 55!28 = !{!"branch_weights", i32 1, i32 0} 56!29 = !{!"branch_weights", i32 50, i32 50} 57!30 = !{!"branch_weights", i32 950, i32 100} 58!31 = !{!"loop_header_weight", i64 1050} 59!32 = !{!"branch_weights", i32 323, i32 627} 60!33 = !{!"loop_header_weight", i64 373} 61!34 = !{!"loop_header_weight", i64 1000} 62!35 = !{!"branch_weights", i32 1, i32 99} 63 64; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreducibleii': 65; CHECK-NEXT: block-frequency-info: _Z11irreducibleii 66; CHECK-NEXT: - entry: {{.*}} count = 1 67; CHECK-NEXT: - entry.for.cond.cleanup_crit_edge: {{.*}} count = 0 68; CHECK-NEXT: - for.cond.cleanup: {{.*}} count = 1 69; CHECK-NEXT: - for.body: {{.*}} count = 100 70; CHECK-NEXT: - for.cond2: {{.*}} count = 1050, irr_loop_header_weight = 1050 71; CHECK-NEXT: - for.body4: {{.*}} count = 950 72; CHECK-NEXT: - entry8: {{.*}} count = 373, irr_loop_header_weight = 373 73; CHECK-NEXT: - if.end9: {{.*}} count = 1000, irr_loop_header_weight = 1000 74; CHECK-NEXT: - for.end: {{.*}} count = 100 75 76@targets = local_unnamed_addr global [256 x i8*] zeroinitializer, align 16 77@tracing = local_unnamed_addr global i32 0, align 4 78 79; Function Attrs: noinline norecurse nounwind uwtable 80define i32 @_Z11irreduciblePh(i8* nocapture readonly %p) !prof !27 { 81entry: 82 %0 = load i32, i32* @tracing, align 4 83 %1 = trunc i32 %0 to i8 84 %tobool = icmp eq i32 %0, 0 85 br label %for.cond1 86 87for.cond1: ; preds = %sw.default, %entry 88 br label %dispatch_op 89 90dispatch_op: ; preds = %sw.bb6, %for.cond1 91 switch i8 %1, label %sw.default [ 92 i8 0, label %sw.bb 93 i8 1, label %dispatch_op.sw.bb6_crit_edge 94 i8 2, label %sw.bb15 95 ], !prof !36 96 97dispatch_op.sw.bb6_crit_edge: ; preds = %dispatch_op 98 br label %sw.bb6 99 100sw.bb: ; preds = %indirectgoto, %dispatch_op 101 br label %exit 102 103TARGET_1: ; preds = %indirectgoto 104 br label %sw.bb6 105 106sw.bb6: ; preds = %TARGET_1, %dispatch_op.sw.bb6_crit_edge 107 br i1 %tobool, label %dispatch_op, label %if.then, !prof !37, !irr_loop !38 108 109if.then: ; preds = %sw.bb6 110 br label %indirectgoto 111 112TARGET_2: ; preds = %indirectgoto 113 br label %sw.bb15 114 115sw.bb15: ; preds = %TARGET_2, %dispatch_op 116 br i1 %tobool, label %if.then18, label %exit, !prof !39, !irr_loop !40 117 118if.then18: ; preds = %sw.bb15 119 br label %indirectgoto 120 121unknown_op: ; preds = %indirectgoto 122 br label %sw.default 123 124sw.default: ; preds = %unknown_op, %dispatch_op 125 br label %for.cond1 126 127exit: ; preds = %sw.bb15, %sw.bb 128 ret i32 0 129 130indirectgoto: ; preds = %if.then18, %if.then 131 %idxprom21 = zext i32 %0 to i64 132 %arrayidx22 = getelementptr inbounds [256 x i8*], [256 x i8*]* @targets, i64 0, i64 %idxprom21 133 %target = load i8*, i8** %arrayidx22, align 8 134 indirectbr i8* %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2], !prof !41, !irr_loop !42 135} 136 137!36 = !{!"branch_weights", i32 0, i32 0, i32 201, i32 1} 138!37 = !{!"branch_weights", i32 201, i32 300} 139!38 = !{!"loop_header_weight", i64 501} 140!39 = !{!"branch_weights", i32 100, i32 0} 141!40 = !{!"loop_header_weight", i64 100} 142!41 = !{!"branch_weights", i32 0, i32 1, i32 300, i32 99} 143!42 = !{!"loop_header_weight", i64 400} 144 145; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreduciblePh': 146; CHECK-NEXT: block-frequency-info: _Z11irreduciblePh 147; CHECK-NEXT: - entry: {{.*}} count = 1 148; CHECK-NEXT: - for.cond1: {{.*}} count = 1 149; CHECK-NEXT: - dispatch_op: {{.*}} count = 202 150; CHECK-NEXT: - dispatch_op.sw.bb6_crit_edge: {{.*}} count = 201 151; CHECK-NEXT: - sw.bb: {{.*}} count = 1 152; CHECK-NEXT: - TARGET_1: {{.*}} count = 300 153; CHECK-NEXT: - sw.bb6: {{.*}} count = 501, irr_loop_header_weight = 501 154; CHECK-NEXT: - if.then: {{.*}} count = 300 155; CHECK-NEXT: - TARGET_2: {{.*}} count = 99 156; CHECK-NEXT: - sw.bb15: {{.*}} count = 100, irr_loop_header_weight = 100 157; CHECK-NEXT: - if.then18: {{.*}} count = 100 158; CHECK-NEXT: - unknown_op: {{.*}} count = 0 159; CHECK-NEXT: - sw.default: {{.*}} count = 0 160; CHECK-NEXT: - exit: {{.*}} count = 1 161; CHECK-NEXT: - indirectgoto: {{.*}} count = 400, irr_loop_header_weight = 400 162 163; Missing some irr loop annotations. 164; Function Attrs: noinline norecurse nounwind uwtable 165define i32 @_Z11irreduciblePh2(i8* nocapture readonly %p) !prof !27 { 166entry: 167 %0 = load i32, i32* @tracing, align 4 168 %1 = trunc i32 %0 to i8 169 %tobool = icmp eq i32 %0, 0 170 br label %for.cond1 171 172for.cond1: ; preds = %sw.default, %entry 173 br label %dispatch_op 174 175dispatch_op: ; preds = %sw.bb6, %for.cond1 176switch i8 %1, label %sw.default [ 177 i8 0, label %sw.bb 178 i8 1, label %dispatch_op.sw.bb6_crit_edge 179 i8 2, label %sw.bb15 180 ], !prof !36 181 182dispatch_op.sw.bb6_crit_edge: ; preds = %dispatch_op 183 br label %sw.bb6 184 185sw.bb: ; preds = %indirectgoto, %dispatch_op 186 br label %exit 187 188TARGET_1: ; preds = %indirectgoto 189 br label %sw.bb6 190 191sw.bb6: ; preds = %TARGET_1, %dispatch_op.sw.bb6_crit_edge 192 br i1 %tobool, label %dispatch_op, label %if.then, !prof !37 ; Missing !irr_loop !38 193 194if.then: ; preds = %sw.bb6 195 br label %indirectgoto 196 197TARGET_2: ; preds = %indirectgoto 198 br label %sw.bb15 199 200sw.bb15: ; preds = %TARGET_2, %dispatch_op 201 br i1 %tobool, label %if.then18, label %exit, !prof !39, !irr_loop !40 202 203if.then18: ; preds = %sw.bb15 204 br label %indirectgoto 205 206unknown_op: ; preds = %indirectgoto 207 br label %sw.default 208 209sw.default: ; preds = %unknown_op, %dispatch_op 210 br label %for.cond1 211 212exit: ; preds = %sw.bb15, %sw.bb 213 ret i32 0 214 215indirectgoto: ; preds = %if.then18, %if.then 216 %idxprom21 = zext i32 %0 to i64 217 %arrayidx22 = getelementptr inbounds [256 x i8*], [256 x i8*]* @targets, i64 0, i64 %idxprom21 218 %target = load i8*, i8** %arrayidx22, align 8 219 indirectbr i8* %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2], !prof !41, !irr_loop !42 220} 221 222; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreduciblePh2': 223; CHECK: block-frequency-info: _Z11irreduciblePh2 224; CHECK: - sw.bb6: {{.*}} count = 100 225; CHECK: - sw.bb15: {{.*}} count = 100, irr_loop_header_weight = 100 226; CHECK: - indirectgoto: {{.*}} count = 400, irr_loop_header_weight = 400 227