xref: /aosp_15_r20/external/llvm/test/Transforms/LICM/funclet.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -licm -S | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,loop(licm)' < %s -S | FileCheck %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5*9880d681SAndroid Build Coastguard Workertarget triple = "i386-pc-windows-msvc18.0.0"
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workerdefine void @test1(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
8*9880d681SAndroid Build Coastguard Workerentry:
9*9880d681SAndroid Build Coastguard Worker  br label %while.cond
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Workerwhile.cond:                                       ; preds = %while.body, %entry
12*9880d681SAndroid Build Coastguard Worker  %0 = call i32 @pure_computation()
13*9880d681SAndroid Build Coastguard Worker  br i1 %b, label %try.cont, label %while.body
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerwhile.body:                                       ; preds = %while.cond
16*9880d681SAndroid Build Coastguard Worker  invoke void @may_throw()
17*9880d681SAndroid Build Coastguard Worker          to label %while.cond unwind label %catch.dispatch
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Workercatch.dispatch:                                   ; preds = %while.body
20*9880d681SAndroid Build Coastguard Worker  %.lcssa1 = phi i32 [ %0, %while.body ]
21*9880d681SAndroid Build Coastguard Worker  %cs = catchswitch within none [label %catch] unwind to caller
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Workercatch:                                            ; preds = %catch.dispatch
24*9880d681SAndroid Build Coastguard Worker  %cp = catchpad within %cs [i8* null, i32 64, i8* null]
25*9880d681SAndroid Build Coastguard Worker  store i32 %.lcssa1, i32* %s
26*9880d681SAndroid Build Coastguard Worker  catchret from %cp to label %try.cont
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Workertry.cont:                                         ; preds = %catch, %while.cond
29*9880d681SAndroid Build Coastguard Worker  ret void
30*9880d681SAndroid Build Coastguard Worker}
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test1(
33*9880d681SAndroid Build Coastguard Worker; CHECK: %[[CALL:.*]] = call i32 @pure_computation()
34*9880d681SAndroid Build Coastguard Worker; CHECK: phi i32 [ %[[CALL]]
35*9880d681SAndroid Build Coastguard Worker
36*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
37*9880d681SAndroid Build Coastguard Workerentry:
38*9880d681SAndroid Build Coastguard Worker  br label %while.cond
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Workerwhile.cond:                                       ; preds = %while.body, %entry
41*9880d681SAndroid Build Coastguard Worker  %0 = call i32 @pure_computation()
42*9880d681SAndroid Build Coastguard Worker  br i1 %b, label %try.cont, label %while.body
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Workerwhile.body:                                       ; preds = %while.cond
45*9880d681SAndroid Build Coastguard Worker  invoke void @may_throw()
46*9880d681SAndroid Build Coastguard Worker          to label %while.cond unwind label %catch.dispatch
47*9880d681SAndroid Build Coastguard Worker
48*9880d681SAndroid Build Coastguard Workercatch.dispatch:                                   ; preds = %while.body
49*9880d681SAndroid Build Coastguard Worker  %.lcssa1 = phi i32 [ %0, %while.body ]
50*9880d681SAndroid Build Coastguard Worker  %cp = cleanuppad within none []
51*9880d681SAndroid Build Coastguard Worker  store i32 %.lcssa1, i32* %s
52*9880d681SAndroid Build Coastguard Worker  cleanupret from %cp unwind to caller
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Workertry.cont:                                         ; preds = %catch, %while.cond
55*9880d681SAndroid Build Coastguard Worker  ret void
56*9880d681SAndroid Build Coastguard Worker}
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test2(
59*9880d681SAndroid Build Coastguard Worker; CHECK:      %[[CP:.*]] = cleanuppad within none []
60*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %[[CALL:.*]] = call i32 @pure_computation() [ "funclet"(token %[[CP]]) ]
61*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: store i32 %[[CALL]], i32* %s
62*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: cleanupret from %[[CP]] unwind to caller
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Workerdefine void @test3(i1 %a, i1 %b, i1 %c) personality i32 (...)* @__CxxFrameHandler3 {
65*9880d681SAndroid Build Coastguard Workerentry:
66*9880d681SAndroid Build Coastguard Worker  %.frame = alloca i8, align 4
67*9880d681SAndroid Build Coastguard Worker  %.frame2 = alloca i8, align 4
68*9880d681SAndroid Build Coastguard Worker  %bc = bitcast i8* %.frame to i32*
69*9880d681SAndroid Build Coastguard Worker  %bc2 = bitcast i8* %.frame2 to i32*
70*9880d681SAndroid Build Coastguard Worker  br i1 %a, label %try.success.or.caught, label %forbody
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Workercatch.object.Throwable:                           ; preds = %catch.dispatch
73*9880d681SAndroid Build Coastguard Worker  %cp = catchpad within %cs [i8* null, i32 64, i8* null]
74*9880d681SAndroid Build Coastguard Worker  unreachable
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Workertry.success.or.caught:                            ; preds = %forcond.backedge, %0
77*9880d681SAndroid Build Coastguard Worker  ret void
78*9880d681SAndroid Build Coastguard Worker
79*9880d681SAndroid Build Coastguard Workerpostinvoke:                                       ; preds = %forbody
80*9880d681SAndroid Build Coastguard Worker  br i1 %b, label %else, label %forcond.backedge
81*9880d681SAndroid Build Coastguard Worker
82*9880d681SAndroid Build Coastguard Workerforcond.backedge:                                 ; preds = %else, %postinvoke
83*9880d681SAndroid Build Coastguard Worker  br i1 %c, label %try.success.or.caught, label %forbody
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Workercatch.dispatch:                                   ; preds = %else, %forbody
86*9880d681SAndroid Build Coastguard Worker  %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller
87*9880d681SAndroid Build Coastguard Worker
88*9880d681SAndroid Build Coastguard Workerforbody:                                          ; preds = %forcond.backedge, %0
89*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* %bc, align 4
90*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* %bc2, align 4
91*9880d681SAndroid Build Coastguard Worker  invoke void @may_throw()
92*9880d681SAndroid Build Coastguard Worker          to label %postinvoke unwind label %catch.dispatch
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Workerelse:                                             ; preds = %postinvoke
95*9880d681SAndroid Build Coastguard Worker  invoke void @may_throw()
96*9880d681SAndroid Build Coastguard Worker          to label %forcond.backedge unwind label %catch.dispatch
97*9880d681SAndroid Build Coastguard Worker}
98*9880d681SAndroid Build Coastguard Worker
99*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @test3(
100*9880d681SAndroid Build Coastguard Worker; CHECK:      catchswitch within none
101*9880d681SAndroid Build Coastguard Worker; CHECK:      store i32 1, i32* %bc, align 4
102*9880d681SAndroid Build Coastguard Worker; CHECK:      store i32 2, i32* %bc2, align 4
103*9880d681SAndroid Build Coastguard Worker
104*9880d681SAndroid Build Coastguard Workerdeclare void @may_throw()
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Workerdeclare i32 @pure_computation() nounwind argmemonly readonly
107*9880d681SAndroid Build Coastguard Worker
108*9880d681SAndroid Build Coastguard Workerdeclare i32 @__CxxFrameHandler3(...)
109