370 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -loop-reduce -S | FileCheck %s3 4target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"5target triple = "i686-pc-windows-msvc"6 7declare i32 @_except_handler3(...)8declare i32 @__CxxFrameHandler3(...)9 10declare void @external(ptr)11declare void @reserve()12 13define void @f() personality ptr @_except_handler3 {14; CHECK-LABEL: @f(15; CHECK-NEXT: entry:16; CHECK-NEXT: br label [[THROW:%.*]]17; CHECK: throw:18; CHECK-NEXT: invoke void @reserve()19; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]20; CHECK: pad:21; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %unreachable] unwind label [[BLAH2:%.*]]22; CHECK: unreachable:23; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []24; CHECK-NEXT: unreachable25; CHECK: blah2:26; CHECK-NEXT: [[CLEANUPPADI4_I_I_I:%.*]] = cleanuppad within none []27; CHECK-NEXT: br label [[LOOP_BODY:%.*]]28; CHECK: loop_body:29; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLAH2]] ]30; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -131; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr32; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null33; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]34; CHECK: iter:35; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]36; CHECK: unwind_out:37; CHECK-NEXT: cleanupret from [[CLEANUPPADI4_I_I_I]] unwind to caller38;39entry:40 br label %throw41 42throw: ; preds = %throw, %entry43 %tmp96 = getelementptr inbounds i8, ptr undef, i32 144 invoke void @reserve()45 to label %throw unwind label %pad46 47pad: ; preds = %throw48 %phi2 = phi ptr [ %tmp96, %throw ]49 %cs = catchswitch within none [label %unreachable] unwind label %blah250 51unreachable:52 catchpad within %cs []53 unreachable54 55blah2:56 %cleanuppadi4.i.i.i = cleanuppad within none []57 br label %loop_body58 59loop_body: ; preds = %iter, %pad60 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blah2 ]61 %tmp100 = icmp eq ptr %tmp99, undef62 br i1 %tmp100, label %unwind_out, label %iter63 64iter: ; preds = %loop_body65 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 166 br i1 true, label %unwind_out, label %loop_body67 68unwind_out: ; preds = %iter, %loop_body69 cleanupret from %cleanuppadi4.i.i.i unwind to caller70}71 72define void @g() personality ptr @_except_handler3 {73; CHECK-LABEL: @g(74; CHECK-NEXT: entry:75; CHECK-NEXT: br label [[THROW:%.*]]76; CHECK: throw:77; CHECK-NEXT: invoke void @reserve()78; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]79; CHECK: pad:80; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blah] unwind to caller81; CHECK: unreachable:82; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []83; CHECK-NEXT: unreachable84; CHECK: blah:85; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []86; CHECK-NEXT: br label [[LOOP_BODY:%.*]]87; CHECK: unwind_out:88; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]89; CHECK: leave:90; CHECK-NEXT: ret void91; CHECK: loop_body:92; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLAH:%.*]] ]93; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -194; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr95; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null96; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]97; CHECK: iter:98; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]99;100entry:101 br label %throw102 103throw: ; preds = %throw, %entry104 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1105 invoke void @reserve()106 to label %throw unwind label %pad107 108pad:109 %phi2 = phi ptr [ %tmp96, %throw ]110 %cs = catchswitch within none [label %unreachable, label %blah] unwind to caller111 112unreachable:113 catchpad within %cs []114 unreachable115 116blah:117 %catchpad = catchpad within %cs []118 br label %loop_body119 120unwind_out:121 catchret from %catchpad to label %leave122 123leave:124 ret void125 126loop_body: ; preds = %iter, %pad127 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blah ]128 %tmp100 = icmp eq ptr %tmp99, undef129 br i1 %tmp100, label %unwind_out, label %iter130 131iter: ; preds = %loop_body132 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1133 br i1 true, label %unwind_out, label %loop_body134}135 136define void @h() personality ptr @_except_handler3 {137; CHECK-LABEL: @h(138; CHECK-NEXT: entry:139; CHECK-NEXT: br label [[THROW:%.*]]140; CHECK: throw:141; CHECK-NEXT: invoke void @reserve()142; CHECK-NEXT: to label [[THROW]] unwind label [[PAD:%.*]]143; CHECK: pad:144; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label [[UNREACHABLE:%.*]], label %blug] unwind to caller145; CHECK: unreachable:146; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []147; CHECK-NEXT: unreachable148; CHECK: blug:149; CHECK-NEXT: [[CATCHPAD:%.*]] = catchpad within [[CS]] []150; CHECK-NEXT: br label [[LOOP_BODY:%.*]]151; CHECK: unwind_out:152; CHECK-NEXT: catchret from [[CATCHPAD]] to label [[LEAVE:%.*]]153; CHECK: leave:154; CHECK-NEXT: ret void155; CHECK: loop_body:156; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[BLUG:%.*]] ]157; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1158; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr159; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null160; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]161; CHECK: iter:162; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]163;164entry:165 br label %throw166 167throw: ; preds = %throw, %entry168 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1169 invoke void @reserve()170 to label %throw unwind label %pad171 172pad:173 %cs = catchswitch within none [label %unreachable, label %blug] unwind to caller174 175unreachable:176 catchpad within %cs []177 unreachable178 179blug:180 %phi2 = phi ptr [ %tmp96, %pad ]181 %catchpad = catchpad within %cs []182 br label %loop_body183 184unwind_out:185 catchret from %catchpad to label %leave186 187leave:188 ret void189 190loop_body: ; preds = %iter, %pad191 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %blug ]192 %tmp100 = icmp eq ptr %tmp99, undef193 br i1 %tmp100, label %unwind_out, label %iter194 195iter: ; preds = %loop_body196 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1197 br i1 true, label %unwind_out, label %loop_body198}199 200define void @i() personality ptr @_except_handler3 {201; CHECK-LABEL: @i(202; CHECK-NEXT: entry:203; CHECK-NEXT: br label [[THROW:%.*]]204; CHECK: throw:205; CHECK-NEXT: invoke void @reserve()206; CHECK-NEXT: to label [[THROW]] unwind label [[CATCHPAD:%.*]]207; CHECK: catchpad:208; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %cp_body] unwind label [[CLEANUPPAD:%.*]]209; CHECK: cp_body:210; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] []211; CHECK-NEXT: br label [[LOOP_HEAD:%.*]]212; CHECK: cleanuppad:213; CHECK-NEXT: [[TMP1:%.*]] = cleanuppad within none []214; CHECK-NEXT: br label [[LOOP_HEAD]]215; CHECK: loop_head:216; CHECK-NEXT: br label [[LOOP_BODY:%.*]]217; CHECK: loop_body:218; CHECK-NEXT: [[LSR_IV:%.*]] = phi i32 [ [[LSR_IV_NEXT:%.*]], [[ITER:%.*]] ], [ 0, [[LOOP_HEAD]] ]219; CHECK-NEXT: [[LSR_IV_NEXT]] = add nuw nsw i32 [[LSR_IV]], -1220; CHECK-NEXT: [[LSR_IV_NEXT1:%.*]] = inttoptr i32 [[LSR_IV_NEXT]] to ptr221; CHECK-NEXT: [[TMP100:%.*]] = icmp eq ptr [[LSR_IV_NEXT1]], null222; CHECK-NEXT: br i1 [[TMP100]], label [[UNWIND_OUT:%.*]], label [[ITER]]223; CHECK: iter:224; CHECK-NEXT: br i1 true, label [[UNWIND_OUT]], label [[LOOP_BODY]]225; CHECK: unwind_out:226; CHECK-NEXT: unreachable227;228entry:229 br label %throw230 231throw: ; preds = %throw, %entry232 %tmp96 = getelementptr inbounds i8, ptr undef, i32 1233 invoke void @reserve()234 to label %throw unwind label %catchpad235 236catchpad: ; preds = %throw237 %phi2 = phi ptr [ %tmp96, %throw ]238 %cs = catchswitch within none [label %cp_body] unwind label %cleanuppad239 240cp_body:241 catchpad within %cs []242 br label %loop_head243 244cleanuppad:245 cleanuppad within none []246 br label %loop_head247 248loop_head:249 br label %loop_body250 251loop_body: ; preds = %iter, %catchpad252 %tmp99 = phi ptr [ %tmp101, %iter ], [ %phi2, %loop_head ]253 %tmp100 = icmp eq ptr %tmp99, undef254 br i1 %tmp100, label %unwind_out, label %iter255 256iter: ; preds = %loop_body257 %tmp101 = getelementptr inbounds i8, ptr %tmp99, i32 1258 br i1 true, label %unwind_out, label %loop_body259 260unwind_out: ; preds = %iter, %loop_body261 unreachable262}263 264define void @test1(ptr %b, ptr %c) personality ptr @__CxxFrameHandler3 {265; CHECK-LABEL: @test1(266; CHECK-NEXT: entry:267; CHECK-NEXT: br label [[FOR_COND:%.*]]268; CHECK: for.cond:269; CHECK-NEXT: [[D_0:%.*]] = phi ptr [ [[B:%.*]], [[ENTRY:%.*]] ], [ [[INCDEC_PTR:%.*]], [[FOR_INC:%.*]] ]270; CHECK-NEXT: invoke void @external(ptr [[D_0]])271; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]272; CHECK: for.inc:273; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i32, ptr [[D_0]], i32 1274; CHECK-NEXT: br label [[FOR_COND]]275; CHECK: catch.dispatch:276; CHECK-NEXT: [[CS:%.*]] = catchswitch within none [label %catch] unwind label [[CATCH_DISPATCH_2:%.*]]277; CHECK: catch:278; CHECK-NEXT: [[TMP0:%.*]] = catchpad within [[CS]] [ptr null, i32 64, ptr null]279; CHECK-NEXT: catchret from [[TMP0]] to label [[TRY_CONT:%.*]]280; CHECK: try.cont:281; CHECK-NEXT: invoke void @external(ptr [[C:%.*]])282; CHECK-NEXT: to label [[TRY_CONT_7:%.*]] unwind label [[CATCH_DISPATCH_2]]283; CHECK: catch.dispatch.2:284; CHECK-NEXT: [[E_0:%.*]] = phi ptr [ [[C]], [[TRY_CONT]] ], [ [[B]], [[CATCH_DISPATCH]] ]285; CHECK-NEXT: [[CS2:%.*]] = catchswitch within none [label %catch.4] unwind to caller286; CHECK: catch.4:287; CHECK-NEXT: [[TMP1:%.*]] = catchpad within [[CS2]] [ptr null, i32 64, ptr null]288; CHECK-NEXT: unreachable289; CHECK: try.cont.7:290; CHECK-NEXT: ret void291;292entry:293 br label %for.cond294 295for.cond: ; preds = %for.inc, %entry296 %d.0 = phi ptr [ %b, %entry ], [ %incdec.ptr, %for.inc ]297 invoke void @external(ptr %d.0)298 to label %for.inc unwind label %catch.dispatch299 300for.inc: ; preds = %for.cond301 %incdec.ptr = getelementptr inbounds i32, ptr %d.0, i32 1302 br label %for.cond303 304catch.dispatch: ; preds = %for.cond305 %cs = catchswitch within none [label %catch] unwind label %catch.dispatch.2306 307catch: ; preds = %catch.dispatch308 %0 = catchpad within %cs [ptr null, i32 64, ptr null]309 catchret from %0 to label %try.cont310 311try.cont: ; preds = %catch312 invoke void @external(ptr %c)313 to label %try.cont.7 unwind label %catch.dispatch.2314 315catch.dispatch.2: ; preds = %try.cont, %catchendblock316 %e.0 = phi ptr [ %c, %try.cont ], [ %b, %catch.dispatch ]317 %cs2 = catchswitch within none [label %catch.4] unwind to caller318 319catch.4: ; preds = %catch.dispatch.2320 catchpad within %cs2 [ptr null, i32 64, ptr null]321 unreachable322 323try.cont.7: ; preds = %try.cont324 ret void325}326 327define i32 @test2() personality ptr @_except_handler3 {328; CHECK-LABEL: @test2(329; CHECK-NEXT: entry:330; CHECK-NEXT: br label [[FOR_BODY:%.*]]331; CHECK: for.body:332; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ 0, [[ENTRY:%.*]] ]333; CHECK-NEXT: invoke void @reserve()334; CHECK-NEXT: to label [[FOR_INC]] unwind label [[CATCH_DISPATCH:%.*]]335; CHECK: catch.dispatch:336; CHECK-NEXT: [[TMP18:%.*]] = catchswitch within none [label %catch.handler] unwind to caller337; CHECK: catch.handler:338; CHECK-NEXT: [[PHI_LCSSA:%.*]] = phi i32 [ [[PHI]], [[CATCH_DISPATCH]] ]339; CHECK-NEXT: [[TMP19:%.*]] = catchpad within [[TMP18]] [ptr null]340; CHECK-NEXT: catchret from [[TMP19]] to label [[DONE:%.*]]341; CHECK: done:342; CHECK-NEXT: ret i32 [[PHI_LCSSA]]343; CHECK: for.inc:344; CHECK-NEXT: [[INC]] = add i32 [[PHI]], 1345; CHECK-NEXT: br label [[FOR_BODY]]346;347entry:348 br label %for.body349 350for.body: ; preds = %for.inc, %entry351 %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]352 invoke void @reserve()353 to label %for.inc unwind label %catch.dispatch354 355catch.dispatch: ; preds = %for.body356 %tmp18 = catchswitch within none [label %catch.handler] unwind to caller357 358catch.handler: ; preds = %catch.dispatch359 %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]360 %tmp19 = catchpad within %tmp18 [ptr null]361 catchret from %tmp19 to label %done362 363done:364 ret i32 %phi.lcssa365 366for.inc: ; preds = %for.body367 %inc = add i32 %phi, 1368 br label %for.body369}370