llvm.org GIT mirror llvm / a9104c6
[PM/LoopUnswitch] Remove a buggy assert in the new loop unswitch. The condition this was asserting doesn't actually hold. I've added comments to explain why, removed the assert, and added a fun test case reduced out of 403.gcc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330564 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 1 year, 4 months ago
2 changed file(s) with 60 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
13631363 continue;
13641364
13651365 // Insert all of the blocks (other than those already present) into
1366 // the loop set. The only block we expect to already be in the set is
1367 // the one we used to find this loop as we immediately handle the
1368 // others the first time we encounter the loop.
1366 // the loop set. We expect at least the block that led us to find the
1367 // inner loop to be in the block set, but we may also have other loop
1368 // blocks if they were already enqueued as predecessors of some other
1369 // outer loop block.
13691370 for (auto *InnerBB : InnerL->blocks()) {
13701371 if (InnerBB == BB) {
13711372 assert(LoopBlockSet.count(InnerBB) &&
13731374 continue;
13741375 }
13751376
1376 bool Inserted = LoopBlockSet.insert(InnerBB).second;
1377 (void)Inserted;
1378 assert(Inserted && "Should only insert an inner loop once!");
1377 LoopBlockSet.insert(InnerBB);
13791378 }
13801379
13811380 // Add the preheader to the worklist so we will continue past the
23792379 loop_exit:
23802380 ret void
23812381 }
2382
2383 ; A test reduced out of 403.gcc with interesting nested loops that trigger
2384 ; multiple unswitches. A key component of this test is that there are multiple
2385 ; paths to reach an inner loop after unswitching, and one of them is via the
2386 ; predecessors of the unswitched loop header. That can allow us to find the loop
2387 ; through multiple different paths.
2388 define void @test21(i1 %a, i1 %b) {
2389 ; CHECK-LABEL: @test21(
2390 bb:
2391 br label %bb3
2392 ; CHECK-NOT: br i1 %a
2393 ;
2394 ; CHECK: br i1 %a, label %[[BB_SPLIT_US:.*]], label %[[BB_SPLIT:.*]]
2395 ;
2396 ; CHECK-NOT: br i1 %a
2397 ; CHECK-NOT: br i1 %b
2398 ;
2399 ; CHECK: [[BB_SPLIT]]:
2400 ; CHECK: br i1 %b
2401 ;
2402 ; CHECK-NOT: br i1 %a
2403 ; CHECK-NOT: br i1 %b
2404
2405 bb3:
2406 %tmp1.0 = phi i32 [ 0, %bb ], [ %tmp1.3, %bb23 ]
2407 br label %bb7
2408
2409 bb7:
2410 %tmp.0 = phi i1 [ true, %bb3 ], [ false, %bb19 ]
2411 %tmp1.1 = phi i32 [ %tmp1.0, %bb3 ], [ %tmp1.2.lcssa, %bb19 ]
2412 br i1 %tmp.0, label %bb11.preheader, label %bb23
2413
2414 bb11.preheader:
2415 br i1 %a, label %bb19, label %bb14.lr.ph
2416
2417 bb14.lr.ph:
2418 br label %bb14
2419
2420 bb14:
2421 %tmp2.02 = phi i32 [ 0, %bb14.lr.ph ], [ 1, %bb14 ]
2422 br i1 %b, label %bb11.bb19_crit_edge, label %bb14
2423
2424 bb11.bb19_crit_edge:
2425 %split = phi i32 [ %tmp2.02, %bb14 ]
2426 br label %bb19
2427
2428 bb19:
2429 %tmp1.2.lcssa = phi i32 [ %split, %bb11.bb19_crit_edge ], [ %tmp1.1, %bb11.preheader ]
2430 %tmp21 = icmp eq i32 %tmp1.2.lcssa, 0
2431 br i1 %tmp21, label %bb23, label %bb7
2432
2433 bb23:
2434 %tmp1.3 = phi i32 [ %tmp1.2.lcssa, %bb19 ], [ %tmp1.1, %bb7 ]
2435 br label %bb3
2436 }