1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -licm -S | FileCheck %s 3; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck %s 4 5target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" 6target triple = "i386-pc-windows-msvc18.0.0" 7 8define void @test1(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 { 9; CHECK-LABEL: @test1( 10; CHECK-NEXT: entry: 11; CHECK-NEXT: [[TMP0:%.*]] = call i32 @pure_computation() 12; CHECK-NEXT: br label [[WHILE_COND:%.*]] 13; CHECK: while.cond: 14; CHECK-NEXT: br i1 [[B:%.*]], label [[TRY_CONT_LOOPEXIT:%.*]], label [[WHILE_BODY:%.*]] 15; CHECK: 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 21; CHECK: catch: 22; CHECK-NEXT: [[CP:%.*]] = catchpad within [[CS]] [i8* null, i32 64, i8* null] 23; CHECK-NEXT: store i32 [[DOTLCSSA1]], i32* [[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]] 27; CHECK: try.cont: 28; CHECK-NEXT: ret void 29; 30entry: 31 br label %while.cond 32 33while.cond: ; preds = %while.body, %entry 34 %0 = call i32 @pure_computation() 35 br i1 %b, label %try.cont, label %while.body 36 37while.body: ; preds = %while.cond 38 invoke void @may_throw() 39 to label %while.cond unwind label %catch.dispatch 40 41catch.dispatch: ; preds = %while.body 42 %.lcssa1 = phi i32 [ %0, %while.body ] 43 %cs = catchswitch within none [label %catch] unwind to caller 44 45catch: ; preds = %catch.dispatch 46 %cp = catchpad within %cs [i8* null, i32 64, i8* null] 47 store i32 %.lcssa1, i32* %s 48 catchret from %cp to label %try.cont 49 50try.cont: ; preds = %catch, %while.cond 51 ret void 52} 53 54define void @test2(i32* %s, i1 %b) personality i32 (...)* @__CxxFrameHandler3 { 55; CHECK-LABEL: @test2( 56; CHECK-NEXT: entry: 57; CHECK-NEXT: br label [[WHILE_COND:%.*]] 58; CHECK: while.cond: 59; CHECK-NEXT: br i1 [[B:%.*]], label [[TRY_CONT:%.*]], label [[WHILE_BODY:%.*]] 60; CHECK: 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]], i32* [[S:%.*]], align 4 67; CHECK-NEXT: cleanupret from [[CP]] unwind to caller 68; CHECK: try.cont: 69; CHECK-NEXT: ret void 70; 71entry: 72 br label %while.cond 73 74while.cond: ; preds = %while.body, %entry 75 %0 = call i32 @pure_computation() 76 br i1 %b, label %try.cont, label %while.body 77 78while.body: ; preds = %while.cond 79 invoke void @may_throw() 80 to label %while.cond unwind label %catch.dispatch 81 82catch.dispatch: ; preds = %while.body 83 %.lcssa1 = phi i32 [ %0, %while.body ] 84 %cp = cleanuppad within none [] 85 store i32 %.lcssa1, i32* %s 86 cleanupret from %cp unwind to caller 87 88try.cont: ; preds = %catch, %while.cond 89 ret void 90} 91 92define void @test3(i1 %a, i1 %b, i1 %c) personality i32 (...)* @__CxxFrameHandler3 { 93; CHECK-LABEL: @test3( 94; CHECK-NEXT: entry: 95; CHECK-NEXT: [[DOTFRAME:%.*]] = alloca i8, align 4 96; CHECK-NEXT: [[DOTFRAME2:%.*]] = alloca i8, align 4 97; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[DOTFRAME]] to i32* 98; CHECK-NEXT: [[BC2:%.*]] = bitcast i8* [[DOTFRAME2]] to i32* 99; CHECK-NEXT: br i1 [[A:%.*]], label [[TRY_SUCCESS_OR_CAUGHT:%.*]], label [[FORBODY_PREHEADER:%.*]] 100; CHECK: forbody.preheader: 101; CHECK-NEXT: store i32 1, i32* [[BC]], align 4 102; CHECK-NEXT: store i32 2, i32* [[BC2]], align 4 103; CHECK-NEXT: br label [[FORBODY:%.*]] 104; CHECK: catch.object.Throwable: 105; CHECK-NEXT: [[CP:%.*]] = catchpad within [[CS:%.*]] [i8* null, i32 64, i8* null] 106; CHECK-NEXT: unreachable 107; CHECK: try.success.or.caught.loopexit: 108; CHECK-NEXT: br label [[TRY_SUCCESS_OR_CAUGHT]] 109; CHECK: try.success.or.caught: 110; CHECK-NEXT: ret void 111; CHECK: postinvoke: 112; CHECK-NEXT: br i1 [[B:%.*]], label [[ELSE:%.*]], label [[FORCOND_BACKEDGE:%.*]] 113; CHECK: forcond.backedge: 114; CHECK-NEXT: br i1 [[C:%.*]], label [[TRY_SUCCESS_OR_CAUGHT_LOOPEXIT:%.*]], label [[FORBODY]] 115; CHECK: catch.dispatch: 116; CHECK-NEXT: [[CS]] = catchswitch within none [label %catch.object.Throwable] unwind to caller 117; CHECK: forbody: 118; CHECK-NEXT: invoke void @may_throw() 119; CHECK-NEXT: to label [[POSTINVOKE:%.*]] unwind label [[CATCH_DISPATCH:%.*]] 120; CHECK: else: 121; CHECK-NEXT: invoke void @may_throw() 122; CHECK-NEXT: to label [[FORCOND_BACKEDGE]] unwind label [[CATCH_DISPATCH]] 123; 124entry: 125 %.frame = alloca i8, align 4 126 %.frame2 = alloca i8, align 4 127 %bc = bitcast i8* %.frame to i32* 128 %bc2 = bitcast i8* %.frame2 to i32* 129 br i1 %a, label %try.success.or.caught, label %forbody 130 131catch.object.Throwable: ; preds = %catch.dispatch 132 %cp = catchpad within %cs [i8* null, i32 64, i8* null] 133 unreachable 134 135try.success.or.caught: ; preds = %forcond.backedge, %0 136 ret void 137 138postinvoke: ; preds = %forbody 139 br i1 %b, label %else, label %forcond.backedge 140 141forcond.backedge: ; preds = %else, %postinvoke 142 br i1 %c, label %try.success.or.caught, label %forbody 143 144catch.dispatch: ; preds = %else, %forbody 145 %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller 146 147forbody: ; preds = %forcond.backedge, %0 148 store i32 1, i32* %bc, align 4 149 store i32 2, i32* %bc2, align 4 150 invoke void @may_throw() 151 to label %postinvoke unwind label %catch.dispatch 152 153else: ; preds = %postinvoke 154 invoke void @may_throw() 155 to label %forcond.backedge unwind label %catch.dispatch 156} 157 158declare void @may_throw() 159 160declare i32 @pure_computation() nounwind argmemonly readonly willreturn 161 162declare i32 @__CxxFrameHandler3(...) 163