1 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY
2 ; RUN: llvm-profdata merge %S/Inputs/landingpad.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-prefixes=GEN,ENTRY
6 ; RUN: llvm-profdata merge %S/Inputs/landingpad_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 @val = global i32 0, align 4
12 @_ZTIi = external constant ptr
13 ; GEN: $__llvm_profile_raw_version = comdat any
14 ; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
15 ; GEN: @__profn_bar = private constant [3 x i8] c"bar"
16 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
18 define i32 @bar(i32 %i) {
21 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_bar, i64 {{[0-9]+}}, i32 2, i32 0)
23 %tobool = icmp ne i32 %rem, 0
24 br i1 %tobool, label %if.then, label %if.end
25 ; USE: br i1 %tobool, label %if.then, label %if.end
26 ; USE-SAME: !prof ![[BW_BAR_ENTRY:[0-9]+]]
30 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_bar, i64 {{[0-9]+}}, i32 2, i32 1)
31 %exception = call ptr @__cxa_allocate_exception(i64 4)
32 store i32 %i, ptr %exception, align 16
33 call void @__cxa_throw(ptr %exception, ptr @_ZTIi, ptr null)
38 ; GEN-NOT: call void @llvm.instrprof.increment
43 declare ptr @__cxa_allocate_exception(i64)
45 declare void @__cxa_throw(ptr, ptr, ptr)
47 define i32 @foo(i32 %i) personality ptr @__gxx_personality_v0 {
50 ; NOTENTRY-NOT: call void @llvm.instrprof.increment
51 ; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 0)
53 %tobool = icmp ne i32 %rem, 0
54 br i1 %tobool, label %if.then, label %if.end
55 ; USE: br i1 %tobool, label %if.then, label %if.end
56 ; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]]
60 ; GEN-NOT: call void @llvm.instrprof.increment
61 %mul = mul nsw i32 %i, 7
62 %call = invoke i32 @bar(i32 %mul)
63 to label %invoke.cont unwind label %lpad
67 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 1)
72 ; GEN-NOT: call void @llvm.instrprof.increment
73 %tmp = landingpad { ptr, i32 }
75 %tmp1 = extractvalue { ptr, i32 } %tmp, 0
76 %tmp2 = extractvalue { ptr, i32 } %tmp, 1
77 br label %catch.dispatch
80 ; GEN: catch.dispatch:
81 ; GEN-NOT: call void @llvm.instrprof.increment
82 %tmp3 = call i32 @llvm.eh.typeid.for(ptr @_ZTIi)
83 %matches = icmp eq i32 %tmp2, %tmp3
84 br i1 %matches, label %catch, label %eh.resume
85 ; USE: br i1 %matches, label %catch, label %eh.resume
86 ; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]]
90 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 2)
91 %tmp4 = call ptr @__cxa_begin_catch(ptr %tmp1)
92 %tmp6 = load i32, ptr %tmp4, align 4
93 %tmp7 = load i32, ptr @val, align 4
94 %sub = sub nsw i32 %tmp7, %tmp6
95 store i32 %sub, ptr @val, align 4
96 call void @__cxa_end_catch()
101 ; GEN-NOT: call void @llvm.instrprof.increment
106 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 0)
107 ; ENTRY-NOT: call void @llvm.instrprof.increment
108 %tmp8 = load i32, ptr @val, align 4
109 %add = add nsw i32 %tmp8, %i
110 store i32 %add, ptr @val, align 4
115 ; GEN: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 3)
116 %lpad.val = insertvalue { ptr, i32 } undef, ptr %tmp1, 0
117 %lpad.val3 = insertvalue { ptr, i32 } %lpad.val, i32 %tmp2, 1
118 resume { ptr, i32 } %lpad.val3
121 declare i32 @__gxx_personality_v0(...)
123 declare i32 @llvm.eh.typeid.for(ptr)
125 declare ptr @__cxa_begin_catch(ptr)
127 declare void @__cxa_end_catch()
129 ; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
130 ; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2}
131 ; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0}