xref: /llvm-project/llvm/test/Transforms/PGOProfile/landingpad.ll (revision 443e2a10f69caeedb9fa621366b16fe0d4358279)
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
4;
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
8target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
9target triple = "x86_64-unknown-linux-gnu"
10
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"
17
18define i32 @bar(i32 %i) {
19entry:
20; GEN: entry:
21; GEN: call void @llvm.instrprof.increment(ptr @__profn_bar, i64 {{[0-9]+}}, i32 2, i32 0)
22  %rem = srem i32 %i, 3
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]+]]
27
28if.then:
29; GEN: if.then:
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)
34  unreachable
35
36if.end:
37; GEN: if.end:
38; GEN-NOT: call void @llvm.instrprof.increment
39; GEN: ret i32
40  ret i32 0
41}
42
43declare ptr @__cxa_allocate_exception(i64)
44
45declare void @__cxa_throw(ptr, ptr, ptr)
46
47define i32 @foo(i32 %i) personality ptr @__gxx_personality_v0 {
48entry:
49; GEN: entry:
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)
52  %rem = srem i32 %i, 2
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]+]]
57
58if.then:
59; GEN: if.then:
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
64
65invoke.cont:
66; GEN: invoke.cont:
67; GEN: call void @llvm.instrprof.increment(ptr @__profn_foo, i64 {{[0-9]+}}, i32 4, i32 1)
68  br label %if.end
69
70lpad:
71; GEN: lpad:
72; GEN-NOT: call void @llvm.instrprof.increment
73  %tmp = landingpad { ptr, i32 }
74          catch ptr @_ZTIi
75  %tmp1 = extractvalue { ptr, i32 } %tmp, 0
76  %tmp2 = extractvalue { ptr, i32 } %tmp, 1
77  br label %catch.dispatch
78
79catch.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]+]]
87
88catch:
89; GEN: catch:
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()
97  br label %try.cont
98
99try.cont:
100; GEN: try.cont:
101; GEN-NOT: call void @llvm.instrprof.increment
102  ret i32 -1
103
104if.end:
105; GEN: if.end:
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
111  br label %try.cont
112
113eh.resume:
114; GEN: eh.resume:
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
119}
120
121declare i32 @__gxx_personality_v0(...)
122
123declare i32 @llvm.eh.typeid.for(ptr)
124
125declare ptr @__cxa_begin_catch(ptr)
126
127declare void @__cxa_end_catch()
128
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}
132