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/landingpad.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 @val = global i32 0, align 4
10 @_ZTIi = external constant i8*
11 ; GEN: $__llvm_profile_raw_version = comdat any
12 ; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
13 ; GEN: @__profn_bar = private constant [3 x i8] c"bar"
14 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
16 define i32 @bar(i32 %i) {
19 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 24868915205, i32 2, i32 0)
21 %tobool = icmp ne i32 %rem, 0
22 br i1 %tobool, label %if.then, label %if.end
23 ; USE: br i1 %tobool, label %if.then, label %if.end
24 ; USE-SAME: !prof ![[BW_BAR_ENTRY:[0-9]+]]
28 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 24868915205, i32 2, i32 1)
29 %exception = call i8* @__cxa_allocate_exception(i64 4)
30 %tmp = bitcast i8* %exception to i32*
31 store i32 %i, i32* %tmp, align 16
32 call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
37 ; GEN-NOT: call void @llvm.instrprof.increment
42 declare i8* @__cxa_allocate_exception(i64)
44 declare void @__cxa_throw(i8*, i8*, i8*)
46 define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
49 ; GEN-NOT: call void @llvm.instrprof.increment
51 %tobool = icmp ne i32 %rem, 0
52 br i1 %tobool, label %if.then, label %if.end
53 ; USE: br i1 %tobool, label %if.then, label %if.end
54 ; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]]
58 ; GEN-NOT: call void @llvm.instrprof.increment
59 %mul = mul nsw i32 %i, 7
60 %call = invoke i32 @bar(i32 %mul)
61 to label %invoke.cont unwind label %lpad
65 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 1)
70 ; GEN-NOT: call void @llvm.instrprof.increment
71 %tmp = landingpad { i8*, i32 }
72 catch i8* bitcast (i8** @_ZTIi to i8*)
73 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
74 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
75 br label %catch.dispatch
78 ; GEN: catch.dispatch:
79 ; GEN-NOT: call void @llvm.instrprof.increment
80 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
81 %matches = icmp eq i32 %tmp2, %tmp3
82 br i1 %matches, label %catch, label %eh.resume
83 ; USE: br i1 %matches, label %catch, label %eh.resume
84 ; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]]
88 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 2)
89 %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1)
90 %tmp5 = bitcast i8* %tmp4 to i32*
91 %tmp6 = load i32, i32* %tmp5, align 4
92 %tmp7 = load i32, i32* @val, align 4
93 %sub = sub nsw i32 %tmp7, %tmp6
94 store i32 %sub, i32* @val, align 4
95 call void @__cxa_end_catch()
100 ; GEN-NOT: call void @llvm.instrprof.increment
105 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 0)
106 %tmp8 = load i32, i32* @val, align 4
107 %add = add nsw i32 %tmp8, %i
108 store i32 %add, i32* @val, align 4
113 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 3)
114 %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0
115 %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1
116 resume { i8*, i32 } %lpad.val3
119 declare i32 @__gxx_personality_v0(...)
121 declare i32 @llvm.eh.typeid.for(i8*)
123 declare i8* @__cxa_begin_catch(i8*)
125 declare void @__cxa_end_catch()
127 ; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
128 ; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2}
129 ; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0}