1 ; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN
2 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -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-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
5 ; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
7 ; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN
8 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN
9 ; RUN: llvm-profdata merge %S/Inputs/criticaledge_entry.proftext -o %t2.profdata
10 ; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
11 ; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
12 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
13 target triple = "x86_64-unknown-linux-gnu"
15 ; GEN: $__llvm_profile_raw_version = comdat any
16 ; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
17 ; GEN: @__profn_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge"
18 ; GEN: @__profn__stdin__bar = private constant [11 x i8] c"<stdin>:bar"
20 define i32 @test_criticalEdge(i32 %i, i32 %j) {
23 ; NOTENTRY-NOT: call void @llvm.instrprof.increment
24 ; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 0)
25 switch i32 %i, label %sw.default [
30 ; CHECK: i32 3, label %entry.sw.bb2_crit_edge
31 ; CHECK: i32 4, label %entry.sw.bb2_crit_edge1
35 ; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
37 ; CHECK: entry.sw.bb2_crit_edge1:
38 ; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 1)
39 ; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 2)
40 ; CHECK: br label %sw.bb2
42 ; CHECK: entry.sw.bb2_crit_edge:
43 ; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 0)
44 ; TENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 1)
45 ; CHECK: br label %sw.bb2
49 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 5)
50 %call = call i32 @bar(i32 2)
55 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 4)
56 %call2 = call i32 @bar(i32 1024)
61 ; GEN-NOT: call void @llvm.instrprof.increment
62 %cmp = icmp eq i32 %j, 2
63 br i1 %cmp, label %if.then, label %if.end
64 ; USE: br i1 %cmp, label %if.then, label %if.end
65 ; USE-SAME: !prof ![[BW_SW_BB2:[0-9]+]]
69 ; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 2)
70 ; ENTRY-NOT: call void @llvm.instrprof.increment
71 %call4 = call i32 @bar(i32 4)
76 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 3)
77 %call5 = call i32 @bar(i32 8)
82 ; GEN-NOT: call void @llvm.instrprof.increment
83 %call6 = call i32 @bar(i32 32)
84 %cmp7 = icmp sgt i32 %j, 10
85 br i1 %cmp7, label %if.then8, label %if.end9
86 ; USE: br i1 %cmp7, label %if.then8, label %if.end9
87 ; USE-SAME: !prof ![[BW_SW_DEFAULT:[0-9]+]]
91 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 7)
92 %add = add nsw i32 %call6, 10
97 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 6)
98 %res.0 = phi i32 [ %add, %if.then8 ], [ %call6, %sw.default ]
103 ; GEN-NOT: call void @llvm.instrprof.increment
104 %res.1 = phi i32 [ %res.0, %if.end9 ], [ %call5, %if.end ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ]
109 ; GEN-NOT: call void @llvm.instrprof.increment
110 %retval = phi i32 [ %res.1, %sw.epilog ], [ %call4, %if.then ]
114 define internal i32 @bar(i32 %i) {
116 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn__stdin__bar, i32 0, i32 0), i64 {{[0-9]+}}, i32 1, i32 0)
120 ; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 2, i32 1, i32 0, i32 2, i32 1, i32 1}
121 ; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i32 2, i32 2}
122 ; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i32 1, i32 1}