1; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY
2; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY
3; RUN: llvm-profdata merge %S/Inputs/landingpad.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
6;
7; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY
8; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY
9; RUN: llvm-profdata merge %S/Inputs/landingpad_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
12target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
13target triple = "x86_64-unknown-linux-gnu"
14
15@val = global i32 0, align 4
16@_ZTIi = external constant i8*
17; GEN: $__llvm_profile_raw_version = comdat any
18; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
19; GEN: @__profn_bar = private constant [3 x i8] c"bar"
20; GEN: @__profn_foo = private constant [3 x i8] c"foo"
21
22define i32 @bar(i32 %i) {
23entry:
24; GEN: entry:
25; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 0)
26  %rem = srem i32 %i, 3
27  %tobool = icmp ne i32 %rem, 0
28  br i1 %tobool, label %if.then, label %if.end
29; USE: br i1 %tobool, label %if.then, label %if.end
30; USE-SAME: !prof ![[BW_BAR_ENTRY:[0-9]+]]
31
32if.then:
33; GEN: if.then:
34; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 1)
35  %exception = call i8* @__cxa_allocate_exception(i64 4)
36  %tmp = bitcast i8* %exception to i32*
37  store i32 %i, i32* %tmp, align 16
38  call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
39  unreachable
40
41if.end:
42; GEN: if.end:
43; GEN-NOT: call void @llvm.instrprof.increment
44; GEN: ret i32
45  ret i32 0
46}
47
48declare i8* @__cxa_allocate_exception(i64)
49
50declare void @__cxa_throw(i8*, i8*, i8*)
51
52define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
53entry:
54; GEN: entry:
55; NOTENTRY-NOT: call void @llvm.instrprof.increment
56; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 {{[0-9]+}}, i32 4, i32 0)
57  %rem = srem i32 %i, 2
58  %tobool = icmp ne i32 %rem, 0
59  br i1 %tobool, label %if.then, label %if.end
60; USE: br i1 %tobool, label %if.then, label %if.end
61; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]]
62
63if.then:
64; GEN: if.then:
65; GEN-NOT: call void @llvm.instrprof.increment
66  %mul = mul nsw i32 %i, 7
67  %call = invoke i32 @bar(i32 %mul)
68          to label %invoke.cont unwind label %lpad
69
70invoke.cont:
71; GEN: invoke.cont:
72; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 {{[0-9]+}}, i32 4, i32 1)
73  br label %if.end
74
75lpad:
76; GEN: lpad:
77; GEN-NOT: call void @llvm.instrprof.increment
78  %tmp = landingpad { i8*, i32 }
79          catch i8* bitcast (i8** @_ZTIi to i8*)
80  %tmp1 = extractvalue { i8*, i32 } %tmp, 0
81  %tmp2 = extractvalue { i8*, i32 } %tmp, 1
82  br label %catch.dispatch
83
84catch.dispatch:
85; GEN: catch.dispatch:
86; GEN-NOT: call void @llvm.instrprof.increment
87  %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
88  %matches = icmp eq i32 %tmp2, %tmp3
89  br i1 %matches, label %catch, label %eh.resume
90; USE: br i1 %matches, label %catch, label %eh.resume
91; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]]
92
93catch:
94; GEN: catch:
95; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 {{[0-9]+}}, i32 4, i32 2)
96  %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1)
97  %tmp5 = bitcast i8* %tmp4 to i32*
98  %tmp6 = load i32, i32* %tmp5, align 4
99  %tmp7 = load i32, i32* @val, align 4
100  %sub = sub nsw i32 %tmp7, %tmp6
101  store i32 %sub, i32* @val, align 4
102  call void @__cxa_end_catch()
103  br label %try.cont
104
105try.cont:
106; GEN: try.cont:
107; GEN-NOT: call void @llvm.instrprof.increment
108  ret i32 -1
109
110if.end:
111; GEN: if.end:
112; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 {{[0-9]+}}, i32 4, i32 0)
113; ENTRY-NOT: call void @llvm.instrprof.increment
114  %tmp8 = load i32, i32* @val, align 4
115  %add = add nsw i32 %tmp8, %i
116  store i32 %add, i32* @val, align 4
117  br label %try.cont
118
119eh.resume:
120; GEN: eh.resume:
121; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 {{[0-9]+}}, i32 4, i32 3)
122  %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0
123  %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1
124  resume { i8*, i32 } %lpad.val3
125}
126
127declare i32 @__gxx_personality_v0(...)
128
129declare i32 @llvm.eh.typeid.for(i8*)
130
131declare i8* @__cxa_begin_catch(i8*)
132
133declare void @__cxa_end_catch()
134
135; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1}
136; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2}
137; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0}
138