xref: /aosp_15_r20/external/llvm/test/Transforms/SimplifyCFG/empty-catchpad.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -simplifycfg -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workerdeclare void @f()
4*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.foo(i32) nounwind
5*9880d681SAndroid Build Coastguard Workerdeclare void @ProcessCLRException()
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workerdefine void @test1() personality void ()* @ProcessCLRException {
8*9880d681SAndroid Build Coastguard Workerentry:
9*9880d681SAndroid Build Coastguard Worker  invoke void @f()
10*9880d681SAndroid Build Coastguard Worker    to label %exit unwind label %exn.dispatch
11*9880d681SAndroid Build Coastguard Workerexn.dispatch:
12*9880d681SAndroid Build Coastguard Worker  %cs = catchswitch within none [label %pad1, label %pad2] unwind to caller
13*9880d681SAndroid Build Coastguard Workerpad1:
14*9880d681SAndroid Build Coastguard Worker  %cp1 = catchpad within %cs [i32 1]
15*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 1)
16*9880d681SAndroid Build Coastguard Worker  catchret from %cp1 to label %exit
17*9880d681SAndroid Build Coastguard Workerpad2:
18*9880d681SAndroid Build Coastguard Worker  %cp2 = catchpad within %cs [i32 2]
19*9880d681SAndroid Build Coastguard Worker  unreachable
20*9880d681SAndroid Build Coastguard Workerexit:
21*9880d681SAndroid Build Coastguard Worker  ret void
22*9880d681SAndroid Build Coastguard Worker}
23*9880d681SAndroid Build Coastguard Worker; Remove unreachble catch2, leave catch1 as-is
24*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test1()
25*9880d681SAndroid Build Coastguard Worker; CHECK: %cs = catchswitch within none [label %pad1] unwind to caller
26*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: catchpad
27*9880d681SAndroid Build Coastguard Worker; CHECK: %cp1 = catchpad within %cs [i32 1]
28*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: catchpad
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker; Remove both catchpads and the catchswitch from exn.dispatch
31*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test2()
32*9880d681SAndroid Build Coastguard Workerdefine void @test2() personality void ()* @ProcessCLRException {
33*9880d681SAndroid Build Coastguard Workerentry:
34*9880d681SAndroid Build Coastguard Worker  invoke void @f()
35*9880d681SAndroid Build Coastguard Worker    to label %via.cleanup unwind label %exn.dispatch
36*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: invoke
37*9880d681SAndroid Build Coastguard Worker  ; CHECK: call void @f()
38*9880d681SAndroid Build Coastguard Workervia.cleanup:
39*9880d681SAndroid Build Coastguard Worker  invoke void @f()
40*9880d681SAndroid Build Coastguard Worker    to label %via.catchswitch unwind label %cleanup.inner
41*9880d681SAndroid Build Coastguard Workercleanup.inner:
42*9880d681SAndroid Build Coastguard Worker  %cp.inner = cleanuppad within none []
43*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 0)
44*9880d681SAndroid Build Coastguard Worker  cleanupret from %cp.inner unwind label %exn.dispatch
45*9880d681SAndroid Build Coastguard Worker  ; CHECK: cleanupret from %cp.inner unwind to caller
46*9880d681SAndroid Build Coastguard Workervia.catchswitch:
47*9880d681SAndroid Build Coastguard Worker  invoke void @f()
48*9880d681SAndroid Build Coastguard Worker    to label %exit unwind label %dispatch.inner
49*9880d681SAndroid Build Coastguard Workerdispatch.inner:
50*9880d681SAndroid Build Coastguard Worker  %cs.inner = catchswitch within none [label %pad.inner] unwind label %exn.dispatch
51*9880d681SAndroid Build Coastguard Worker  ; CHECK: %cs.inner = catchswitch within none [label %pad.inner] unwind to caller
52*9880d681SAndroid Build Coastguard Workerpad.inner:
53*9880d681SAndroid Build Coastguard Worker  %catch.inner = catchpad within %cs.inner [i32 0]
54*9880d681SAndroid Build Coastguard Worker  ; CHECK: %catch.inner = catchpad within %cs.inner
55*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 1)
56*9880d681SAndroid Build Coastguard Worker  catchret from %catch.inner to label %exit
57*9880d681SAndroid Build Coastguard Workerexn.dispatch:
58*9880d681SAndroid Build Coastguard Worker  %cs = catchswitch within none [label %pad1, label %pad2] unwind to caller
59*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: catchswitch within
60*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: catchpad
61*9880d681SAndroid Build Coastguard Workerpad1:
62*9880d681SAndroid Build Coastguard Worker  catchpad within %cs [i32 1]
63*9880d681SAndroid Build Coastguard Worker  unreachable
64*9880d681SAndroid Build Coastguard Workerpad2:
65*9880d681SAndroid Build Coastguard Worker  catchpad within %cs [i32 2]
66*9880d681SAndroid Build Coastguard Worker  unreachable
67*9880d681SAndroid Build Coastguard Workerexit:
68*9880d681SAndroid Build Coastguard Worker  ret void
69*9880d681SAndroid Build Coastguard Worker}
70*9880d681SAndroid Build Coastguard Worker
71*9880d681SAndroid Build Coastguard Worker; Same as @test2, but exn.dispatch catchswitch has an unwind dest that
72*9880d681SAndroid Build Coastguard Worker; preds need to be reidrected to
73*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test3()
74*9880d681SAndroid Build Coastguard Workerdefine void @test3() personality void ()* @ProcessCLRException {
75*9880d681SAndroid Build Coastguard Workerentry:
76*9880d681SAndroid Build Coastguard Worker  invoke void @f()
77*9880d681SAndroid Build Coastguard Worker    to label %via.cleanup unwind label %exn.dispatch
78*9880d681SAndroid Build Coastguard Worker  ; CHECK: invoke void @f()
79*9880d681SAndroid Build Coastguard Worker  ; CHECK-NEXT: to label %via.cleanup unwind label %cleanup
80*9880d681SAndroid Build Coastguard Workervia.cleanup:
81*9880d681SAndroid Build Coastguard Worker  invoke void @f()
82*9880d681SAndroid Build Coastguard Worker    to label %via.catchswitch unwind label %cleanup.inner
83*9880d681SAndroid Build Coastguard Workercleanup.inner:
84*9880d681SAndroid Build Coastguard Worker  %cp.inner = cleanuppad within none []
85*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 0)
86*9880d681SAndroid Build Coastguard Worker  cleanupret from %cp.inner unwind label %exn.dispatch
87*9880d681SAndroid Build Coastguard Worker  ; CHECK: cleanupret from %cp.inner unwind label %cleanup
88*9880d681SAndroid Build Coastguard Workervia.catchswitch:
89*9880d681SAndroid Build Coastguard Worker  invoke void @f()
90*9880d681SAndroid Build Coastguard Worker    to label %exit unwind label %dispatch.inner
91*9880d681SAndroid Build Coastguard Workerdispatch.inner:
92*9880d681SAndroid Build Coastguard Worker  %cs.inner = catchswitch within none [label %pad.inner] unwind label %exn.dispatch
93*9880d681SAndroid Build Coastguard Worker  ; CHECK: %cs.inner = catchswitch within none [label %pad.inner] unwind label %cleanup
94*9880d681SAndroid Build Coastguard Workerpad.inner:
95*9880d681SAndroid Build Coastguard Worker  %catch.inner = catchpad within %cs.inner [i32 0]
96*9880d681SAndroid Build Coastguard Worker  ; CHECK: %catch.inner = catchpad within %cs.inner
97*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 1)
98*9880d681SAndroid Build Coastguard Worker  catchret from %catch.inner to label %exit
99*9880d681SAndroid Build Coastguard Workerexn.dispatch:
100*9880d681SAndroid Build Coastguard Worker  %cs = catchswitch within none [label %pad1, label %pad2] unwind label %cleanup
101*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: catchswitch within
102*9880d681SAndroid Build Coastguard Worker  ; CHECK-NOT: catchpad
103*9880d681SAndroid Build Coastguard Workerpad1:
104*9880d681SAndroid Build Coastguard Worker  catchpad within %cs [i32 1]
105*9880d681SAndroid Build Coastguard Worker  unreachable
106*9880d681SAndroid Build Coastguard Workerpad2:
107*9880d681SAndroid Build Coastguard Worker  catchpad within %cs [i32 2]
108*9880d681SAndroid Build Coastguard Worker  unreachable
109*9880d681SAndroid Build Coastguard Workercleanup:
110*9880d681SAndroid Build Coastguard Worker  %cp = cleanuppad within none []
111*9880d681SAndroid Build Coastguard Worker  call void @llvm.foo(i32 0)
112*9880d681SAndroid Build Coastguard Worker  cleanupret from %cp unwind to caller
113*9880d681SAndroid Build Coastguard Workerexit:
114*9880d681SAndroid Build Coastguard Worker  ret void
115*9880d681SAndroid Build Coastguard Worker}
116