1; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN 2; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN 3; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata 4; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 5; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 7target triple = "x86_64-unknown-linux-gnu" 8 9; GEN: $__llvm_profile_raw_version = comdat any 10; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat 11; GEN: @__profn_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge" 12; GEN: @__profn__stdin__bar = private constant [11 x i8] c"<stdin>:bar" 13 14define i32 @test_criticalEdge(i32 %i, i32 %j) { 15entry: 16; CHECK: entry: 17; GEN-NOT: call void @llvm.instrprof.increment 18 switch i32 %i, label %sw.default [ 19 i32 1, label %sw.bb 20 i32 2, label %sw.bb1 21 i32 3, label %sw.bb2 22 i32 4, label %sw.bb2 23; CHECK: i32 3, label %entry.sw.bb2_crit_edge 24; CHECK: i32 4, label %entry.sw.bb2_crit_edge1 25 i32 5, label %sw.bb2 26 ] 27; USE: ] 28; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]] 29 30; CHECK: entry.sw.bb2_crit_edge1: 31; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 1) 32; CHECK: br label %sw.bb2 33 34; CHECK: entry.sw.bb2_crit_edge: 35; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 0) 36; CHECK: br label %sw.bb2 37 38sw.bb: 39; GEN: sw.bb: 40; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 5) 41 %call = call i32 @bar(i32 2) 42 br label %sw.epilog 43 44sw.bb1: 45; GEN: sw.bb1: 46; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 4) 47 %call2 = call i32 @bar(i32 1024) 48 br label %sw.epilog 49 50sw.bb2: 51; GEN: sw.bb2: 52; GEN-NOT: call void @llvm.instrprof.increment 53 %cmp = icmp eq i32 %j, 2 54 br i1 %cmp, label %if.then, label %if.end 55; USE: br i1 %cmp, label %if.then, label %if.end 56; USE-SAME: !prof ![[BW_SW_BB2:[0-9]+]] 57 58if.then: 59; GEN: if.then: 60; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 2) 61 %call4 = call i32 @bar(i32 4) 62 br label %return 63 64if.end: 65; GEN: if.end: 66; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 3) 67 %call5 = call i32 @bar(i32 8) 68 br label %sw.epilog 69 70sw.default: 71; GEN: sw.default: 72; GEN-NOT: call void @llvm.instrprof.increment 73 %call6 = call i32 @bar(i32 32) 74 %cmp7 = icmp sgt i32 %j, 10 75 br i1 %cmp7, label %if.then8, label %if.end9 76; USE: br i1 %cmp7, label %if.then8, label %if.end9 77; USE-SAME: !prof ![[BW_SW_DEFAULT:[0-9]+]] 78 79if.then8: 80; GEN: if.then8: 81; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 7) 82 %add = add nsw i32 %call6, 10 83 br label %if.end9 84 85if.end9: 86; GEN: if.end9: 87; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 82323253069, i32 8, i32 6) 88 %res.0 = phi i32 [ %add, %if.then8 ], [ %call6, %sw.default ] 89 br label %sw.epilog 90 91sw.epilog: 92; GEN: sw.epilog: 93; GEN-NOT: call void @llvm.instrprof.increment 94 %res.1 = phi i32 [ %res.0, %if.end9 ], [ %call5, %if.end ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ] 95 br label %return 96 97return: 98; GEN: return: 99; GEN-NOT: call void @llvm.instrprof.increment 100 %retval = phi i32 [ %res.1, %sw.epilog ], [ %call4, %if.then ] 101 ret i32 %retval 102} 103 104define internal i32 @bar(i32 %i) { 105entry: 106; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn__stdin__bar, i32 0, i32 0), i64 12884901887, i32 1, i32 0) 107 ret i32 %i 108} 109 110; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 2, i32 1, i32 0, i32 2, i32 1, i32 1} 111; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i32 2, i32 2} 112; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i32 1, i32 1} 113