llvm.org GIT mirror llvm / eceadea
[PM/LoopUnswitch] Remove another over-aggressive assert. This code path can very clearly be called in a context where we have baselined all the cloned blocks to a particular loop and are trying to handle nested subloops. There is no harm in this, so just relax the assert. I've added a test case that will make sure we actually exercise this code path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330680 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 1 year, 4 months ago
2 changed file(s) with 74 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
912912 for (auto *BB : OrigL.blocks()) {
913913 auto *ClonedBB = cast(VMap.lookup(BB));
914914 ClonedL.addBlockEntry(ClonedBB);
915 if (LI.getLoopFor(BB) == &OrigL) {
916 assert(!LI.getLoopFor(ClonedBB) &&
917 "Should not have an existing loop for this block!");
915 if (LI.getLoopFor(BB) == &OrigL)
918916 LI.changeLoopFor(ClonedBB, &ClonedL);
919 }
920917 }
921918 };
922919
24342434 %tmp1.3 = phi i32 [ %tmp1.2.lcssa, %bb19 ], [ %tmp1.1, %bb7 ]
24352435 br label %bb3
24362436 }
2437
2438 ; A test reduced out of 400.perlbench that when unswitching the `%stop`
2439 ; condition clones a loop nest outside of a containing loop. This excercises a
2440 ; different cloning path from our other test cases and in turn verifying the
2441 ; resulting structure can catch any failures to correctly clone these nested
2442 ; loops.
2443 declare void @f()
2444 declare void @g()
2445 declare i32 @h(i32 %arg)
2446 define void @test22(i32 %arg) {
2447 ; CHECK-LABEL: define void @test22(
2448 entry:
2449 br label %loop1.header
2450
2451 loop1.header:
2452 %stop = phi i1 [ true, %loop1.latch ], [ false, %entry ]
2453 %i = phi i32 [ %i.lcssa, %loop1.latch ], [ %arg, %entry ]
2454 ; CHECK: %[[I:.*]] = phi i32 [ %{{.*}}, %loop1.latch ], [ %arg, %entry ]
2455 br i1 %stop, label %loop1.exit, label %loop1.body.loop2.ph
2456 ; CHECK: br i1 %stop, label %loop1.exit, label %loop1.body.loop2.ph
2457
2458 loop1.body.loop2.ph:
2459 br label %loop2.header
2460 ; Just check that the we unswitched the key condition and that leads to the
2461 ; inner loop header.
2462 ;
2463 ; CHECK: loop1.body.loop2.ph:
2464 ; CHECK-NEXT: br i1 %stop, label %[[SPLIT_US:.*]], label %[[SPLIT:.*]]
2465 ;
2466 ; CHECK: [[SPLIT_US]]:
2467 ; CHECK-NEXT: br label %[[LOOP2_HEADER_US:.*]]
2468 ;
2469 ; CHECK: [[LOOP2_HEADER_US]]:
2470 ; CHECK-NEXT: %{{.*}} = phi i32 [ %[[I]], %[[SPLIT_US]] ]
2471 ;
2472 ; CHECK: [[SPLIT]]:
2473 ; CHECK-NEXT: br label %[[LOOP2_HEADER:.*]]
2474 ;
2475 ; CHECK: [[LOOP2_HEADER]]:
2476 ; CHECK-NEXT: %{{.*}} = phi i32 [ %[[I]], %[[SPLIT]] ]
2477
2478 loop2.header:
2479 %i.inner = phi i32 [ %i, %loop1.body.loop2.ph ], [ %i.next, %loop2.latch ]
2480 br label %loop3.header
2481
2482 loop3.header:
2483 %sw = call i32 @h(i32 %i.inner)
2484 switch i32 %sw, label %loop3.exit [
2485 i32 32, label %loop3.header
2486 i32 59, label %loop2.latch
2487 i32 36, label %loop1.latch
2488 ]
2489
2490 loop2.latch:
2491 %i.next = add i32 %i.inner, 1
2492 br i1 %stop, label %loop2.exit, label %loop2.header
2493
2494 loop1.latch:
2495 %i.lcssa = phi i32 [ %i.inner, %loop3.header ]
2496 br label %loop1.header
2497
2498 loop3.exit:
2499 call void @f()
2500 ret void
2501
2502 loop2.exit:
2503 call void @g()
2504 ret void
2505
2506 loop1.exit:
2507 call void @g()
2508 ret void
2509 }