1 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN
2 ; RUN: llvm-profdata merge %S/Inputs/criticaledge.proftext -o %t.profdata
3 ; RUN: opt < %s -passes=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-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN
6 ; RUN: llvm-profdata merge %S/Inputs/criticaledge_entry.proftext -o %t2.profdata
7 ; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
8 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-unknown-linux-gnu"
11 ; GEN: $__llvm_profile_raw_version = comdat any
12 ; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
13 ; GEN: @__profn_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge"
14 ; GEN: @__profn__stdin__bar = private constant [11 x i8] c"<stdin>;bar"
16 define i32 @test_criticalEdge(i32 %i, i32 %j) {
19 ; NOTENTRY-NOT: call void @llvm.instrprof.increment
20 ; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 0)
21 switch i32 %i, label %sw.default [
26 ; CHECK: i32 3, label %entry.sw.bb2_crit_edge
27 ; CHECK: i32 4, label %entry.sw.bb2_crit_edge1
31 ; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
33 ; CHECK: entry.sw.bb2_crit_edge1:
34 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 1)
35 ; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 2)
36 ; CHECK: br label %sw.bb2
38 ; CHECK: entry.sw.bb2_crit_edge:
39 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 0)
40 ; TENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 1)
41 ; CHECK: br label %sw.bb2
45 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 5)
46 %call = call i32 @bar(i32 2)
51 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 6)
52 %call2 = call i32 @bar(i32 1024)
57 ; GEN-NOT: call void @llvm.instrprof.increment
58 %cmp = icmp eq i32 %j, 2
59 br i1 %cmp, label %if.then, label %if.end
60 ; USE: br i1 %cmp, label %if.then, label %if.end
61 ; USE-SAME: !prof ![[BW_SW_BB2:[0-9]+]]
65 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 2)
66 ; ENTRY-NOT: call void @llvm.instrprof.increment
67 %call4 = call i32 @bar(i32 4)
72 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 3)
73 %call5 = call i32 @bar(i32 8)
78 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 4)
79 %call6 = call i32 @bar(i32 32)
80 %cmp7 = icmp sgt i32 %j, 10
81 br i1 %cmp7, label %if.then8, label %if.end9
82 ; USE: br i1 %cmp7, label %if.then8, label %if.end9
83 ; USE-SAME: !prof ![[BW_SW_DEFAULT:[0-9]+]]
87 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_test_criticalEdge, i64 {{[0-9]+}}, i32 8, i32 7)
88 %add = add nsw i32 %call6, 10
93 ; GEN-NOT: call void @llvm.instrprof.increment
94 %res.0 = phi i32 [ %add, %if.then8 ], [ %call6, %sw.default ]
99 ; GEN-NOT: call void @llvm.instrprof.increment
100 %res.1 = phi i32 [ %res.0, %if.end9 ], [ %call5, %if.end ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ]
105 ; GEN-NOT: call void @llvm.instrprof.increment
106 %retval = phi i32 [ %res.1, %sw.epilog ], [ %call4, %if.then ]
110 define internal i32 @bar(i32 %i) {
112 ; GEN: call void @llvm.instrprof.increment(ptr @__profn__stdin__bar, i64 {{[0-9]+}}, i32 1, i32 0)
116 ; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 2, i32 1, i32 0, i32 2, i32 1, i32 1}
117 ; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i32 2, i32 2}
118 ; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i32 1, i32 1}