xref: /llvm-project/llvm/test/Transforms/GlobalMerge/eh-filter.ll (revision bd9e14574a80d3c022d796d373aa92bdc63f4c26)
1; REQUIRES: asserts
2; RUN: opt -global-merge -debug-only=global-merge -S -o - %s 2>&1 | FileCheck %s
3; RUN: opt -passes='global-merge' -debug-only=global-merge -S -o - %s 2>&1 | FileCheck %s
4
5;; Checks from the debug info.
6; CHECK:      Number of GV that must be kept:  5
7; CHECK-NEXT: Kept: @_ZTIi = external constant ptr
8; CHECK-NEXT: Kept: @_ZTIf = external constant ptr
9; CHECK-NEXT: Kept: @_ZTId = external constant ptr
10; CHECK-NEXT: Kept: @_ZTIc = external constant ptr
11; CHECK-NEXT: Kept: @_ZTIPi = external constant ptr
12
13;; Check that the landingpad, catch and filter have not changed.
14; CHECK:      %0 = landingpad { ptr, i32 }
15; CHECK-NEXT:         catch ptr @_ZTIi
16; CHECK-NEXT:         filter [5 x ptr] [ptr @_ZTIi, ptr @_ZTIf, ptr @_ZTId, ptr @_ZTIc, ptr @_ZTIPi]
17
18@_ZTIi = external constant ptr
19@_ZTIf = external constant ptr
20@_ZTId = external constant ptr
21@_ZTIc = external constant ptr
22@_ZTIPi = external constant ptr
23
24define noundef signext i32 @_Z6calleri(i32 noundef signext %a) local_unnamed_addr personality ptr @__xlcxx_personality_v1 {
25entry:
26  invoke void @_Z16callee_can_throwi(i32 noundef signext %a)
27          to label %return unwind label %lpad
28
29lpad:                                             ; preds = %entry
30  %0 = landingpad { ptr, i32 }
31          catch ptr @_ZTIi
32          filter [5 x ptr] [ptr @_ZTIi, ptr @_ZTIf, ptr @_ZTId, ptr @_ZTIc, ptr @_ZTIPi]
33  %1 = extractvalue { ptr, i32 } %0, 0
34  %2 = extractvalue { ptr, i32 } %0, 1
35  %3 = tail call i32 @llvm.eh.typeid.for(ptr nonnull @_ZTIi)
36  %matches = icmp eq i32 %2, %3
37  br i1 %matches, label %catch, label %filter.dispatch
38
39filter.dispatch:                                  ; preds = %lpad
40  %ehspec.fails = icmp slt i32 %2, 0
41  br i1 %ehspec.fails, label %ehspec.unexpected, label %eh.resume
42
43ehspec.unexpected:                                ; preds = %filter.dispatch
44  tail call void @__cxa_call_unexpected(ptr %1)
45  unreachable
46
47catch:                                            ; preds = %lpad
48  %4 = tail call ptr @__cxa_begin_catch(ptr %1)
49  %5 = load i32, ptr %4, align 4
50  tail call void @__cxa_end_catch()
51  br label %return
52
53return:                                           ; preds = %entry, %catch
54  %retval.0 = phi i32 [ %5, %catch ], [ 0, %entry ]
55  ret i32 %retval.0
56
57eh.resume:                                        ; preds = %filter.dispatch
58  resume { ptr, i32 } %0
59}
60
61declare void @_Z16callee_can_throwi(i32 noundef signext) local_unnamed_addr
62
63declare i32 @__xlcxx_personality_v1(...)
64
65declare i32 @llvm.eh.typeid.for(ptr)
66
67declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr
68
69declare void @__cxa_end_catch() local_unnamed_addr
70
71declare void @__cxa_call_unexpected(ptr) local_unnamed_addr
72