1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=licm -S | FileCheck %s
3 ; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<target-ir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s
5 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
6 target triple = "i386-pc-windows-msvc18.0.0"
8 define void @test1(ptr %s, i1 %b) personality ptr @__CxxFrameHandler3 {
11 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @pure_computation()
12 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
14 ; CHECK-NEXT: br i1 [[B:%.*]], label [[TRY_CONT_LOOPEXIT:%.*]], label [[WHILE_BODY:%.*]]
16 ; CHECK-NEXT: invoke void @may_throw()
17 ; CHECK-NEXT: to label [[WHILE_COND]] unwind label [[CATCH_DISPATCH:%.*]]
18 ; CHECK: catch.dispatch:
19 ; CHECK-NEXT: [[DOTLCSSA1:%.*]] = phi i32 [ [[TMP0]], [[WHILE_BODY]] ]
20 ; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %catch] unwind to caller
22 ; CHECK-NEXT: [[CP:%.*]] = catchpad within [[CS]] [ptr null, i32 64, ptr null]
23 ; CHECK-NEXT: store i32 [[DOTLCSSA1]], ptr [[S:%.*]], align 4
24 ; CHECK-NEXT: catchret from [[CP]] to label [[TRY_CONT:%.*]]
25 ; CHECK: try.cont.loopexit:
26 ; CHECK-NEXT: br label [[TRY_CONT]]
28 ; CHECK-NEXT: ret void
33 while.cond: ; preds = %while.body, %entry
34 %0 = call i32 @pure_computation()
35 br i1 %b, label %try.cont, label %while.body
37 while.body: ; preds = %while.cond
38 invoke void @may_throw()
39 to label %while.cond unwind label %catch.dispatch
41 catch.dispatch: ; preds = %while.body
42 %.lcssa1 = phi i32 [ %0, %while.body ]
43 %cs = catchswitch within none [label %catch] unwind to caller
45 catch: ; preds = %catch.dispatch
46 %cp = catchpad within %cs [ptr null, i32 64, ptr null]
47 store i32 %.lcssa1, ptr %s
48 catchret from %cp to label %try.cont
50 try.cont: ; preds = %catch, %while.cond
54 define void @test2(ptr %s, i1 %b) personality ptr @__CxxFrameHandler3 {
55 ; CHECK-LABEL: @test2(
57 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
59 ; CHECK-NEXT: br i1 [[B:%.*]], label [[TRY_CONT:%.*]], label [[WHILE_BODY:%.*]]
61 ; CHECK-NEXT: invoke void @may_throw()
62 ; CHECK-NEXT: to label [[WHILE_COND]] unwind label [[CATCH_DISPATCH:%.*]]
63 ; CHECK: catch.dispatch:
64 ; CHECK-NEXT: [[CP:%.*]] = cleanuppad within none []
65 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @pure_computation() [ "funclet"(token [[CP]]) ]
66 ; CHECK-NEXT: store i32 [[TMP0]], ptr [[S:%.*]], align 4
67 ; CHECK-NEXT: cleanupret from [[CP]] unwind to caller
69 ; CHECK-NEXT: ret void
74 while.cond: ; preds = %while.body, %entry
75 %0 = call i32 @pure_computation()
76 br i1 %b, label %try.cont, label %while.body
78 while.body: ; preds = %while.cond
79 invoke void @may_throw()
80 to label %while.cond unwind label %catch.dispatch
82 catch.dispatch: ; preds = %while.body
83 %.lcssa1 = phi i32 [ %0, %while.body ]
84 %cp = cleanuppad within none []
85 store i32 %.lcssa1, ptr %s
86 cleanupret from %cp unwind to caller
88 try.cont: ; preds = %catch, %while.cond
92 define void @test3(i1 %a, i1 %b, i1 %c) personality ptr @__CxxFrameHandler3 {
93 ; CHECK-LABEL: @test3(
95 ; CHECK-NEXT: [[DOTFRAME:%.*]] = alloca i8, align 4
96 ; CHECK-NEXT: [[DOTFRAME2:%.*]] = alloca i8, align 4
97 ; CHECK-NEXT: br i1 [[A:%.*]], label [[TRY_SUCCESS_OR_CAUGHT:%.*]], label [[FORBODY_PREHEADER:%.*]]
98 ; CHECK: forbody.preheader:
99 ; CHECK-NEXT: store i32 1, ptr [[DOTFRAME]], align 4
100 ; CHECK-NEXT: store i32 2, ptr [[DOTFRAME2]], align 4
101 ; CHECK-NEXT: br label [[FORBODY:%.*]]
102 ; CHECK: catch.object.Throwable:
103 ; CHECK-NEXT: [[CP:%.*]] = catchpad within [[CS:%.*]] [ptr null, i32 64, ptr null]
104 ; CHECK-NEXT: unreachable
105 ; CHECK: try.success.or.caught.loopexit:
106 ; CHECK-NEXT: br label [[TRY_SUCCESS_OR_CAUGHT]]
107 ; CHECK: try.success.or.caught:
108 ; CHECK-NEXT: ret void
110 ; CHECK-NEXT: br i1 [[B:%.*]], label [[ELSE:%.*]], label [[FORCOND_BACKEDGE:%.*]]
111 ; CHECK: forcond.backedge:
112 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TRY_SUCCESS_OR_CAUGHT_LOOPEXIT:%.*]], label [[FORBODY]]
113 ; CHECK: catch.dispatch:
114 ; CHECK-NEXT: [[CS]] = catchswitch within none [label %catch.object.Throwable] unwind to caller
116 ; CHECK-NEXT: invoke void @may_throw()
117 ; CHECK-NEXT: to label [[POSTINVOKE:%.*]] unwind label [[CATCH_DISPATCH:%.*]]
119 ; CHECK-NEXT: invoke void @may_throw()
120 ; CHECK-NEXT: to label [[FORCOND_BACKEDGE]] unwind label [[CATCH_DISPATCH]]
123 %.frame = alloca i8, align 4
124 %.frame2 = alloca i8, align 4
125 br i1 %a, label %try.success.or.caught, label %forbody
127 catch.object.Throwable: ; preds = %catch.dispatch
128 %cp = catchpad within %cs [ptr null, i32 64, ptr null]
131 try.success.or.caught: ; preds = %forcond.backedge, %0
134 postinvoke: ; preds = %forbody
135 br i1 %b, label %else, label %forcond.backedge
137 forcond.backedge: ; preds = %else, %postinvoke
138 br i1 %c, label %try.success.or.caught, label %forbody
140 catch.dispatch: ; preds = %else, %forbody
141 %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller
143 forbody: ; preds = %forcond.backedge, %0
144 store i32 1, ptr %.frame, align 4
145 store i32 2, ptr %.frame2, align 4
146 invoke void @may_throw()
147 to label %postinvoke unwind label %catch.dispatch
149 else: ; preds = %postinvoke
150 invoke void @may_throw()
151 to label %forcond.backedge unwind label %catch.dispatch
154 declare void @may_throw()
156 declare i32 @pure_computation() nounwind argmemonly readonly willreturn
158 declare i32 @__CxxFrameHandler3(...)