1 ; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
2 ; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata
3 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 @val = global i32 0, align 4
8 @_ZTIi = external constant i8*
9 ; GEN: @__profn_bar = private constant [3 x i8] c"bar"
10 ; GEN: @__profn_foo = private constant [3 x i8] c"foo"
12 define i32 @bar(i32 %i) {
15 ; GEN-NOT: call void @llvm.instrprof.increment
17 %tobool = icmp ne i32 %rem, 0
18 br i1 %tobool, label %if.then, label %if.end
19 ; USE: br i1 %tobool, label %if.then, label %if.end
20 ; USE-SAME: !prof ![[BW_BAR_ENTRY:[0-9]+]]
24 ; 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)
25 %exception = call i8* @__cxa_allocate_exception(i64 4)
26 %tmp = bitcast i8* %exception to i32*
27 store i32 %i, i32* %tmp, align 16
28 call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
33 ; 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)
37 declare i8* @__cxa_allocate_exception(i64)
39 declare void @__cxa_throw(i8*, i8*, i8*)
41 define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
44 ; GEN-NOT: call void @llvm.instrprof.increment
46 %tobool = icmp ne i32 %rem, 0
47 br i1 %tobool, label %if.then, label %if.end
48 ; USE: br i1 %tobool, label %if.then, label %if.end
49 ; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]]
53 ; GEN-NOT: call void @llvm.instrprof.increment
54 %mul = mul nsw i32 %i, 7
55 %call = invoke i32 @bar(i32 %mul)
56 to label %invoke.cont unwind label %lpad
60 ; 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)
65 ; GEN-NOT: call void @llvm.instrprof.increment
66 %tmp = landingpad { i8*, i32 }
67 catch i8* bitcast (i8** @_ZTIi to i8*)
68 %tmp1 = extractvalue { i8*, i32 } %tmp, 0
69 %tmp2 = extractvalue { i8*, i32 } %tmp, 1
70 br label %catch.dispatch
73 ; GEN: catch.dispatch:
74 ; GEN-NOT: call void @llvm.instrprof.increment
75 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
76 %matches = icmp eq i32 %tmp2, %tmp3
77 br i1 %matches, label %catch, label %eh.resume
78 ; USE: br i1 %matches, label %catch, label %eh.resume
79 ; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]]
83 ; 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)
84 %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1)
85 %tmp5 = bitcast i8* %tmp4 to i32*
86 %tmp6 = load i32, i32* %tmp5, align 4
87 %tmp7 = load i32, i32* @val, align 4
88 %sub = sub nsw i32 %tmp7, %tmp6
89 store i32 %sub, i32* @val, align 4
90 call void @__cxa_end_catch()
95 ; GEN-NOT: call void @llvm.instrprof.increment
100 ; 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)
101 %tmp8 = load i32, i32* @val, align 4
102 %add = add nsw i32 %tmp8, %i
103 store i32 %add, i32* @val, align 4
108 ; 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)
109 %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0
110 %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1
111 resume { i8*, i32 } %lpad.val3
114 declare i32 @__gxx_personality_v0(...)
116 declare i32 @llvm.eh.typeid.for(i8*)
118 declare i8* @__cxa_begin_catch(i8*)
120 declare void @__cxa_end_catch()
122 ; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
123 ; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2}
124 ; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0}