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
6 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-unknown-linux-gnu"
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"
14 define i32 @test_criticalEdge(i32 %i, i32 %j) {
17 ; GEN-NOT: call void @llvm.instrprof.increment
18 switch i32 %i, label %sw.default [
23 ; CHECK: i32 3, label %entry.sw.bb2_crit_edge
24 ; CHECK: i32 4, label %entry.sw.bb2_crit_edge1
28 ; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
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
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
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)
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)
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]+]]
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)
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)
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]+]]
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
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 ]
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 ]
99 ; GEN-NOT: call void @llvm.instrprof.increment
100 %retval = phi i32 [ %res.1, %sw.epilog ], [ %call4, %if.then ]
104 define internal i32 @bar(i32 %i) {
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)
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}