[PGO] Shorten profile symbol prefixes
[oota-llvm.git] / test / Transforms / PGOProfile / landingpad.ll
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"
6
7 @val = global i32 0, align 4
8 @_ZTIi = external constant i8*
9 ; GEN: @__prf_nm_bar = private constant [3 x i8] c"bar"
10 ; GEN: @__prf_nm_foo = private constant [3 x i8] c"foo"
11
12 define i32 @bar(i32 %i) {
13 entry:
14 ; GEN: entry:
15 ; GEN-NOT: call void @llvm.instrprof.increment
16   %rem = srem i32 %i, 3
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]+]]
21
22 if.then:
23 ; GEN: if.then:
24 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_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)
29   unreachable
30
31 if.end:
32 ; GEN: if.end:
33 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_bar, i32 0, i32 0), i64 24868915205, i32 2, i32 0)
34   ret i32 0
35 }
36
37 declare i8* @__cxa_allocate_exception(i64)
38
39 declare void @__cxa_throw(i8*, i8*, i8*)
40
41 define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
42 entry:
43 ; GEN: entry:
44 ; GEN-NOT: call void @llvm.instrprof.increment
45   %rem = srem i32 %i, 2
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]+]]
50
51 if.then:
52 ; GEN: if.then:
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
57
58 invoke.cont:
59 ; GEN: invoke.cont:
60 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 1)
61   br label %if.end
62
63 lpad:
64 ; GEN: lpad:
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
71
72 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]+]]
80
81 catch:
82 ; GEN: catch:
83 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_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()
91   br label %try.cont
92
93 try.cont:
94 ; GEN: try.cont:
95 ; GEN-NOT: call void @llvm.instrprof.increment
96   ret i32 -1
97
98 if.end:
99 ; GEN: if.end:
100 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_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
104   br label %try.cont
105
106 eh.resume:
107 ; GEN: eh.resume:
108 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__prf_nm_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
112 }
113
114 declare i32 @__gxx_personality_v0(...)
115
116 declare i32 @llvm.eh.typeid.for(i8*)
117
118 declare i8* @__cxa_begin_catch(i8*)
119
120 declare void @__cxa_end_catch()
121
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}