xref: /llvm-project/llvm/test/Transforms/PGOProfile/icp_invoke.ll (revision 9ff36df5a4a7d52c51e950522870bb64912688d2)
1cee313d2SEric Christopher; RUN: opt < %s -icp-lto -passes=pgo-icall-prom -S | FileCheck %s --check-prefix=ICP
27b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
3cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu"
4cee313d2SEric Christopher
5*9ff36df5SFangrui Song@foo1 = global ptr null, align 8
6*9ff36df5SFangrui Song@foo2 = global ptr null, align 8
7*9ff36df5SFangrui Song@_ZTIi = external constant ptr
8cee313d2SEric Christopher
9cee313d2SEric Christopherdefine internal void @_ZL4bar1v() !PGOFuncName !0 {
10cee313d2SEric Christopherentry:
11cee313d2SEric Christopher  ret void
12cee313d2SEric Christopher}
13cee313d2SEric Christopher
14cee313d2SEric Christopherdefine internal i32 @_ZL4bar2v() !PGOFuncName !1 {
15cee313d2SEric Christopherentry:
16cee313d2SEric Christopher  ret i32 100
17cee313d2SEric Christopher}
18cee313d2SEric Christopher
19*9ff36df5SFangrui Songdefine i32 @_Z3goov() personality ptr @__gxx_personality_v0 {
20cee313d2SEric Christopherentry:
21*9ff36df5SFangrui Song  %tmp = load ptr, ptr @foo1, align 8
22*9ff36df5SFangrui Song; ICP:  [[CMP_IC1:%[0-9]+]] = icmp eq ptr %tmp, @_ZL4bar1v
23cee313d2SEric Christopher; ICP:  br i1 [[CMP_IC1]], label %[[TRUE_LABEL_IC1:.*]], label %[[FALSE_LABEL_IC1:.*]], !prof [[BRANCH_WEIGHT:![0-9]+]]
24cee313d2SEric Christopher; ICP:[[TRUE_LABEL_IC1]]:
25cee313d2SEric Christopher; ICP:  invoke void @_ZL4bar1v()
26cee313d2SEric Christopher; ICP:          to label %[[DCALL_NORMAL_DEST_IC1:.*]] unwind label %lpad
27cee313d2SEric Christopher; ICP:[[FALSE_LABEL_IC1]]:
28cee313d2SEric Christopher  invoke void %tmp()
29cee313d2SEric Christopher          to label %try.cont unwind label %lpad, !prof !2
30cee313d2SEric Christopher
31cee313d2SEric Christopher; ICP:[[DCALL_NORMAL_DEST_IC1]]:
32cee313d2SEric Christopher; ICP:  br label %try.cont
33cee313d2SEric Christopher
34cee313d2SEric Christopherlpad:
35*9ff36df5SFangrui Song  %tmp1 = landingpad { ptr, i32 }
36*9ff36df5SFangrui Song          catch ptr @_ZTIi
37*9ff36df5SFangrui Song  %tmp2 = extractvalue { ptr, i32 } %tmp1, 0
38*9ff36df5SFangrui Song  %tmp3 = extractvalue { ptr, i32 } %tmp1, 1
39*9ff36df5SFangrui Song  %tmp4 = tail call i32 @llvm.eh.typeid.for(ptr @_ZTIi)
40cee313d2SEric Christopher  %matches = icmp eq i32 %tmp3, %tmp4
41cee313d2SEric Christopher  br i1 %matches, label %catch, label %eh.resume
42cee313d2SEric Christopher
43cee313d2SEric Christophercatch:
44*9ff36df5SFangrui Song  %tmp5 = tail call ptr @__cxa_begin_catch(ptr %tmp2)
45cee313d2SEric Christopher  tail call void @__cxa_end_catch()
46cee313d2SEric Christopher  br label %try.cont
47cee313d2SEric Christopher
48cee313d2SEric Christophertry.cont:
49*9ff36df5SFangrui Song  %tmp6 = load ptr, ptr @foo2, align 8
50*9ff36df5SFangrui Song; ICP:  [[CMP_IC2:%[0-9]+]] = icmp eq ptr %tmp6, @_ZL4bar2v
51cee313d2SEric Christopher; ICP:  br i1 [[CMP_IC2]], label %[[TRUE_LABEL_IC2:.*]], label %[[FALSE_LABEL_IC2:.*]], !prof [[BRANCH_WEIGHT:![0-9]+]]
52cee313d2SEric Christopher; ICP:[[TRUE_LABEL_IC2]]:
53cee313d2SEric Christopher; ICP:  [[RESULT_IC2_0:%[0-9]+]] = invoke i32 @_ZL4bar2v()
54cee313d2SEric Christopher; ICP:          to label %[[MERGE_BB:.*]] unwind label %lpad1
55cee313d2SEric Christopher; ICP:[[FALSE_LABEL_IC2]]:
56cee313d2SEric Christopher; ICP:  [[RESULT_IC2_1:%.+]] = invoke i32 %tmp6()
57cee313d2SEric Christopher; ICP:          to label %[[MERGE_BB]] unwind label %lpad1
58cee313d2SEric Christopher  %call = invoke i32 %tmp6()
59cee313d2SEric Christopher          to label %try.cont8 unwind label %lpad1, !prof !3
60cee313d2SEric Christopher
61cee313d2SEric Christopher; ICP:[[MERGE_BB]]:
62cee313d2SEric Christopher; ICP:  [[MERGE_PHI:%.+]] = phi i32 [ [[RESULT_IC2_1]], %[[FALSE_LABEL_IC2]] ], [ [[RESULT_IC2_0]], %[[TRUE_LABEL_IC2]] ]
63cee313d2SEric Christopher; ICP:  br label %try.cont8
64cee313d2SEric Christopherlpad1:
65*9ff36df5SFangrui Song  %tmp7 = landingpad { ptr, i32 }
66*9ff36df5SFangrui Song          catch ptr @_ZTIi
67*9ff36df5SFangrui Song  %tmp8 = extractvalue { ptr, i32 } %tmp7, 0
68*9ff36df5SFangrui Song  %tmp9 = extractvalue { ptr, i32 } %tmp7, 1
69*9ff36df5SFangrui Song  %tmp10 = tail call i32 @llvm.eh.typeid.for(ptr @_ZTIi)
70cee313d2SEric Christopher  %matches5 = icmp eq i32 %tmp9, %tmp10
71cee313d2SEric Christopher  br i1 %matches5, label %catch6, label %eh.resume
72cee313d2SEric Christopher
73cee313d2SEric Christophercatch6:
74*9ff36df5SFangrui Song  %tmp11 = tail call ptr @__cxa_begin_catch(ptr %tmp8)
75cee313d2SEric Christopher  tail call void @__cxa_end_catch()
76cee313d2SEric Christopher  br label %try.cont8
77cee313d2SEric Christopher
78cee313d2SEric Christophertry.cont8:
79cee313d2SEric Christopher  %i.0 = phi i32 [ undef, %catch6 ], [ %call, %try.cont ]
80cee313d2SEric Christopher; ICP:  %i.0 = phi i32 [ undef, %catch6 ], [ [[MERGE_PHI]], %[[MERGE_BB]] ]
81cee313d2SEric Christopher  ret i32 %i.0
82cee313d2SEric Christopher
83cee313d2SEric Christophereh.resume:
84cee313d2SEric Christopher  %ehselector.slot.0 = phi i32 [ %tmp9, %lpad1 ], [ %tmp3, %lpad ]
85*9ff36df5SFangrui Song  %exn.slot.0 = phi ptr [ %tmp8, %lpad1 ], [ %tmp2, %lpad ]
86*9ff36df5SFangrui Song  %lpad.val = insertvalue { ptr, i32 } undef, ptr %exn.slot.0, 0
87*9ff36df5SFangrui Song  %lpad.val11 = insertvalue { ptr, i32 } %lpad.val, i32 %ehselector.slot.0, 1
88*9ff36df5SFangrui Song  resume { ptr, i32 } %lpad.val11
89cee313d2SEric Christopher}
90cee313d2SEric Christopher
91cee313d2SEric Christopherdeclare i32 @__gxx_personality_v0(...)
92cee313d2SEric Christopher
93*9ff36df5SFangrui Songdeclare i32 @llvm.eh.typeid.for(ptr)
94cee313d2SEric Christopher
95*9ff36df5SFangrui Songdeclare ptr @__cxa_begin_catch(ptr)
96cee313d2SEric Christopher
97cee313d2SEric Christopherdeclare void @__cxa_end_catch()
98cee313d2SEric Christopher
99cee313d2SEric Christopher!0 = !{!"invoke.ll:_ZL4bar1v"}
100cee313d2SEric Christopher!1 = !{!"invoke.ll:_ZL4bar2v"}
101cee313d2SEric Christopher!2 = !{!"VP", i32 0, i64 1, i64 -2732222848796217051, i64 1}
102cee313d2SEric Christopher!3 = !{!"VP", i32 0, i64 1, i64 -6116256810522035449, i64 1}
1037c5d2becSJonathan Roelofs; ICP-NOT: !3 = !{!"VP", i32 0, i64 1, i64 -2732222848796217051, i64 1}
1047c5d2becSJonathan Roelofs; ICP-NOT: !4 = !{!"VP", i32 0, i64 1, i64 -6116256810522035449, i64 1}
1055c31b8b9SArthur Eubanks; ICP: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 0}
106