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 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(ptr %s, i1 %b) personality ptr @__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]] [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]] 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 [ptr null, i32 64, ptr null] 47 store i32 %.lcssa1, ptr %s 48 catchret from %cp to label %try.cont 49 50try.cont: ; preds = %catch, %while.cond 51 ret void 52} 53 54define void @test2(ptr %s, i1 %b) personality ptr @__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]], ptr [[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, ptr %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 ptr @__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: 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 109; CHECK: postinvoke: 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 115; CHECK: forbody: 116; CHECK-NEXT: invoke void @may_throw() 117; CHECK-NEXT: to label [[POSTINVOKE:%.*]] unwind label [[CATCH_DISPATCH:%.*]] 118; CHECK: else: 119; CHECK-NEXT: invoke void @may_throw() 120; CHECK-NEXT: to label [[FORCOND_BACKEDGE]] unwind label [[CATCH_DISPATCH]] 121; 122entry: 123 %.frame = alloca i8, align 4 124 %.frame2 = alloca i8, align 4 125 br i1 %a, label %try.success.or.caught, label %forbody 126 127catch.object.Throwable: ; preds = %catch.dispatch 128 %cp = catchpad within %cs [ptr null, i32 64, ptr null] 129 unreachable 130 131try.success.or.caught: ; preds = %forcond.backedge, %0 132 ret void 133 134postinvoke: ; preds = %forbody 135 br i1 %b, label %else, label %forcond.backedge 136 137forcond.backedge: ; preds = %else, %postinvoke 138 br i1 %c, label %try.success.or.caught, label %forbody 139 140catch.dispatch: ; preds = %else, %forbody 141 %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller 142 143forbody: ; 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 148 149else: ; preds = %postinvoke 150 invoke void @may_throw() 151 to label %forcond.backedge unwind label %catch.dispatch 152} 153 154declare void @may_throw() 155 156declare i32 @pure_computation() nounwind argmemonly readonly willreturn 157 158declare i32 @__CxxFrameHandler3(...) 159