@@ -501,8 +501,12 @@ void VPlanTransforms::prepareForVectorization(
501
501
cast<VPBasicBlock>(HeaderVPB),
502
502
cast<VPBasicBlock>(LatchVPB), Range);
503
503
HandledUncountableEarlyExit = true ;
504
+ } else {
505
+ for (VPRecipeBase &R : cast<VPIRBasicBlock>(EB)->phis ()) {
506
+ if (auto *PhiR = dyn_cast<VPIRPhi>(&R))
507
+ PhiR->removeIncomingValue (Pred);
508
+ }
504
509
}
505
-
506
510
cast<VPBasicBlock>(Pred)->getTerminator ()->eraseFromParent ();
507
511
VPBlockUtils::disconnectBlocks (Pred, EB);
508
512
}
@@ -535,45 +539,33 @@ void VPlanTransforms::prepareForVectorization(
535
539
// Thus if tail is to be folded, we know we don't need to run the
536
540
// remainder and we can set the condition to true.
537
541
// 3) Otherwise, construct a runtime check.
538
-
539
- if (!RequiresScalarEpilogueCheck) {
540
- if (auto *LatchExitVPB = MiddleVPBB->getSingleSuccessor ())
541
- VPBlockUtils::disconnectBlocks (MiddleVPBB, LatchExitVPB);
542
- VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
543
- VPBlockUtils::connectBlocks (Plan.getEntry (), ScalarPH);
544
- Plan.getEntry ()->swapSuccessors ();
545
-
546
- // The exit blocks are unreachable, remove their recipes to make sure no
547
- // users remain that may pessimize transforms.
548
- for (auto *EB : Plan.getExitBlocks ()) {
549
- for (VPRecipeBase &R : make_early_inc_range (*EB))
550
- R.eraseFromParent ();
551
- }
552
- return ;
553
- }
554
-
555
- // The connection order corresponds to the operands of the conditional branch,
556
- // with the middle block already connected to the exit block.
557
542
VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
558
543
// Also connect the entry block to the scalar preheader.
559
544
// TODO: Also introduce a branch recipe together with the minimum trip count
560
545
// check.
561
546
VPBlockUtils::connectBlocks (Plan.getEntry (), ScalarPH);
562
547
Plan.getEntry ()->swapSuccessors ();
563
548
549
+ if (MiddleVPBB->getNumSuccessors () != 2 )
550
+ return ;
551
+
564
552
auto *ScalarLatchTerm = TheLoop->getLoopLatch ()->getTerminator ();
565
553
// Here we use the same DebugLoc as the scalar loop latch terminator instead
566
554
// of the corresponding compare because they may have ended up with
567
555
// different line numbers and we want to avoid awkward line stepping while
568
556
// debugging. Eg. if the compare has got a line number inside the loop.
569
557
VPBuilder Builder (MiddleVPBB);
570
- VPValue *Cmp =
571
- TailFolded
572
- ? Plan.getOrAddLiveIn (ConstantInt::getTrue (
573
- IntegerType::getInt1Ty (TripCount->getType ()->getContext ())))
574
- : Builder.createICmp (CmpInst::ICMP_EQ, Plan.getTripCount (),
575
- &Plan.getVectorTripCount (),
576
- ScalarLatchTerm->getDebugLoc (), " cmp.n" );
558
+ VPValue *Cmp;
559
+ if (TailFolded)
560
+ Cmp = Plan.getOrAddLiveIn (ConstantInt::getTrue (
561
+ IntegerType::getInt1Ty (TripCount->getType ()->getContext ())));
562
+ else if (!RequiresScalarEpilogueCheck)
563
+ Cmp = Plan.getOrAddLiveIn (ConstantInt::getFalse (
564
+ IntegerType::getInt1Ty (TripCount->getType ()->getContext ())));
565
+ else
566
+ Cmp = Builder.createICmp (CmpInst::ICMP_EQ, Plan.getTripCount (),
567
+ &Plan.getVectorTripCount (),
568
+ ScalarLatchTerm->getDebugLoc (), " cmp.n" );
577
569
Builder.createNaryOp (VPInstruction::BranchOnCond, {Cmp},
578
570
ScalarLatchTerm->getDebugLoc ());
579
571
}
0 commit comments