@@ -2458,68 +2458,42 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
2458
2458
R->eraseFromParent ();
2459
2459
}
2460
2460
2461
- void VPlanTransforms::handleUncountableEarlyExit (VPlan &Plan,
2461
+ void VPlanTransforms::handleUncountableEarlyExit (VPBasicBlock *EarlyExitingVPBB,
2462
+ VPBasicBlock *EarlyExitVPBB,
2463
+
2464
+ VPlan &Plan,
2462
2465
VPBasicBlock *HeaderVPBB,
2463
2466
VPBasicBlock *LatchVPBB,
2464
2467
VFRange &Range) {
2465
- // First find the uncountable early exiting block by looking at the
2466
- // predecessors of the exit blocks.
2467
- VPBlockBase *MiddleVPBB = LatchVPBB->getSuccessors ()[0 ];
2468
- VPBasicBlock *EarlyExitingVPBB = nullptr ;
2469
- VPIRBasicBlock *EarlyExitVPBB = nullptr ;
2470
- for (auto *EB : Plan.getExitBlocks ()) {
2471
- for (VPBlockBase *Pred : EB->getPredecessors ()) {
2472
- if (Pred != MiddleVPBB) {
2473
- EarlyExitingVPBB = cast<VPBasicBlock>(Pred);
2474
- EarlyExitVPBB = EB;
2475
- break ;
2476
- }
2477
- }
2478
- }
2479
- assert (EarlyExitVPBB && " Must have a early exiting block." );
2480
- assert (all_of (Plan.getExitBlocks (),
2481
- [EarlyExitingVPBB, MiddleVPBB](VPIRBasicBlock *EB) {
2482
- return all_of (
2483
- EB->getPredecessors (),
2484
- [EarlyExitingVPBB, MiddleVPBB](VPBlockBase *Pred) {
2485
- return Pred == EarlyExitingVPBB || Pred == MiddleVPBB;
2486
- });
2487
- }) &&
2488
- " All exit blocks must only have EarlyExitingVPBB or MiddleVPBB as "
2489
- " predecessors." );
2490
-
2491
- VPBuilder Builder (LatchVPBB->getTerminator ());
2492
- VPBlockBase *TrueSucc = EarlyExitingVPBB->getSuccessors ()[0 ];
2493
- VPValue *EarlyExitCond = EarlyExitingVPBB->getTerminator ()->getOperand (0 );
2494
- auto *EarlyExitTakenCond = TrueSucc == EarlyExitVPBB
2495
- ? EarlyExitCond
2496
- : Builder.createNot (EarlyExitCond);
2468
+ using namespace llvm ::VPlanPatternMatch;
2497
2469
2470
+ VPBlockBase *MiddleVPBB = LatchVPBB->getSuccessors ()[0 ];
2498
2471
if (!EarlyExitVPBB->getSinglePredecessor () &&
2499
2472
EarlyExitVPBB->getPredecessors ()[0 ] != MiddleVPBB) {
2500
- for (VPRecipeBase &R : EarlyExitVPBB->phis ()) {
2501
- // Early exit operand should always be last, i.e., 0 if EarlyExitVPBB has
2502
- // a single predecessor and 1 if it has two.
2503
- // If EarlyExitVPBB has two predecessors, they are already ordered such
2504
- // that early exit is second (and latch exit is first), by construction.
2505
- // But its underlying IRBB (EarlyExitIRBB) may have its predecessors
2506
- // ordered the other way around, and it is the order of the latter which
2507
- // corresponds to the order of operands of EarlyExitVPBB's phi recipes.
2508
- // Therefore, if early exit (UncountableExitingBlock) is the first
2509
- // predecessor of EarlyExitIRBB, we swap the operands of phi recipes,
2510
- // thereby bringing them to match EarlyExitVPBB's predecessor order,
2511
- // with early exit being last (second). Otherwise they already match.
2473
+ // Early exit operand should always be last phi operand. If EarlyExitVPBB
2474
+ // has two predecessors and MiddleVPBB isn't the first, swap the operands of
2475
+ // the phis.
2476
+ for (VPRecipeBase &R : EarlyExitVPBB->phis ())
2512
2477
cast<VPIRPhi>(&R)->swapOperands ();
2513
- }
2514
2478
}
2515
2479
2480
+ VPBuilder Builder (LatchVPBB->getTerminator ());
2481
+ VPBlockBase *TrueSucc = EarlyExitingVPBB->getSuccessors ()[0 ];
2482
+ assert (
2483
+ match (EarlyExitingVPBB->getTerminator (), m_BranchOnCond (m_VPValue ())) &&
2484
+ " Terminator must be be BranchOnCond" );
2485
+ VPValue *CondOfEarlyExitingVPBB =
2486
+ EarlyExitingVPBB->getTerminator ()->getOperand (0 );
2487
+ auto *CondToEarlyExit = TrueSucc == EarlyExitVPBB
2488
+ ? CondOfEarlyExitingVPBB
2489
+ : Builder.createNot (CondOfEarlyExitingVPBB);
2516
2490
EarlyExitingVPBB->getTerminator ()->eraseFromParent ();
2517
2491
VPBlockUtils::disconnectBlocks (EarlyExitingVPBB, EarlyExitVPBB);
2518
2492
2519
2493
// Split the middle block and have it conditionally branch to the early exit
2520
2494
// block if EarlyExitTaken.
2521
2495
VPValue *IsEarlyExitTaken =
2522
- Builder.createNaryOp (VPInstruction::AnyOf, {EarlyExitTakenCond });
2496
+ Builder.createNaryOp (VPInstruction::AnyOf, {CondToEarlyExit });
2523
2497
VPBasicBlock *NewMiddle = Plan.createVPBasicBlock (" middle.split" );
2524
2498
VPBasicBlock *VectorEarlyExitVPBB =
2525
2499
Plan.createVPBasicBlock (" vector.early.exit" );
@@ -2537,7 +2511,7 @@ void VPlanTransforms::handleUncountableEarlyExit(VPlan &Plan,
2537
2511
// Early exit operand should always be last, i.e., 0 if EarlyExitVPBB has
2538
2512
// a single predecessor and 1 if it has two.
2539
2513
unsigned EarlyExitIdx = ExitIRI->getNumOperands () - 1 ;
2540
- if (!EarlyExitVPBB-> getSinglePredecessor () ) {
2514
+ if (ExitIRI-> getNumOperands () != 1 ) {
2541
2515
// The first of two operands corresponds to the latch exit, via MiddleVPBB
2542
2516
// predecessor. Extract its last lane.
2543
2517
ExitIRI->extractLastLaneOfFirstOperand (MiddleBuilder);
@@ -2553,7 +2527,7 @@ void VPlanTransforms::handleUncountableEarlyExit(VPlan &Plan,
2553
2527
LoopVectorizationPlanner::getDecisionAndClampRange (IsVector, Range)) {
2554
2528
// Update the incoming value from the early exit.
2555
2529
VPValue *FirstActiveLane = EarlyExitB.createNaryOp (
2556
- VPInstruction::FirstActiveLane, {EarlyExitTakenCond }, nullptr ,
2530
+ VPInstruction::FirstActiveLane, {CondToEarlyExit }, nullptr ,
2557
2531
" first.active.lane" );
2558
2532
IncomingFromEarlyExit = EarlyExitB.createNaryOp (
2559
2533
Instruction::ExtractElement, {IncomingFromEarlyExit, FirstActiveLane},
0 commit comments