1 ; RUN: opt < %s -licm -S | FileCheck %s
2 ; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck %s
4 target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
5 target triple = "i386-pc-windows-msvc18.0.0"
7 define void @test1(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
11 while.cond: ; preds = %while.body, %entry
12 %0 = call i32 @pure_computation()
13 br i1 %b, label %try.cont, label %while.body
15 while.body: ; preds = %while.cond
16 invoke void @may_throw()
17 to label %while.cond unwind label %catch.dispatch
19 catch.dispatch: ; preds = %while.body
20 %.lcssa1 = phi i32 [ %0, %while.body ]
21 %cs = catchswitch within none [label %catch] unwind to caller
23 catch: ; preds = %catch.dispatch
24 %cp = catchpad within %cs [i8* null, i32 64, i8* null]
25 store i32 %.lcssa1, i32* %s
26 catchret from %cp to label %try.cont
28 try.cont: ; preds = %catch, %while.cond
32 ; CHECK-LABEL: define void @test1(
33 ; CHECK: %[[CALL:.*]] = call i32 @pure_computation()
34 ; CHECK: phi i32 [ %[[CALL]]
36 define void @test2(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 {
40 while.cond: ; preds = %while.body, %entry
41 %0 = call i32 @pure_computation()
42 br i1 %b, label %try.cont, label %while.body
44 while.body: ; preds = %while.cond
45 invoke void @may_throw()
46 to label %while.cond unwind label %catch.dispatch
48 catch.dispatch: ; preds = %while.body
49 %.lcssa1 = phi i32 [ %0, %while.body ]
50 %cp = cleanuppad within none []
51 store i32 %.lcssa1, i32* %s
52 cleanupret from %cp unwind to caller
54 try.cont: ; preds = %catch, %while.cond
58 ; CHECK-LABEL: define void @test2(
59 ; CHECK: %[[CP:.*]] = cleanuppad within none []
60 ; CHECK-NEXT: %[[CALL:.*]] = call i32 @pure_computation() [ "funclet"(token %[[CP]]) ]
61 ; CHECK-NEXT: store i32 %[[CALL]], i32* %s
62 ; CHECK-NEXT: cleanupret from %[[CP]] unwind to caller
64 define void @test3(i1 %a, i1 %b, i1 %c) personality i32 (...)* @__CxxFrameHandler3 {
66 %.frame = alloca i8, align 4
67 %.frame2 = alloca i8, align 4
68 %bc = bitcast i8* %.frame to i32*
69 %bc2 = bitcast i8* %.frame2 to i32*
70 br i1 %a, label %try.success.or.caught, label %forbody
72 catch.object.Throwable: ; preds = %catch.dispatch
73 %cp = catchpad within %cs [i8* null, i32 64, i8* null]
76 try.success.or.caught: ; preds = %forcond.backedge, %0
79 postinvoke: ; preds = %forbody
80 br i1 %b, label %else, label %forcond.backedge
82 forcond.backedge: ; preds = %else, %postinvoke
83 br i1 %c, label %try.success.or.caught, label %forbody
85 catch.dispatch: ; preds = %else, %forbody
86 %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller
88 forbody: ; preds = %forcond.backedge, %0
89 store i32 1, i32* %bc, align 4
90 store i32 2, i32* %bc2, align 4
91 invoke void @may_throw()
92 to label %postinvoke unwind label %catch.dispatch
94 else: ; preds = %postinvoke
95 invoke void @may_throw()
96 to label %forcond.backedge unwind label %catch.dispatch
99 ; CHECK-LABEL: define void @test3(
100 ; CHECK-LABEL: forbody.preheader:
101 ; CHECK: store i32 1, i32* %bc, align 4
102 ; CHECK: store i32 2, i32* %bc2, align 4
103 ; CHECK: catchswitch within none
104 ; CHECK-LABEL: forbody:
106 declare void @may_throw()
108 declare i32 @pure_computation() nounwind argmemonly readonly
110 declare i32 @__CxxFrameHandler3(...)