@@ -501,8 +501,12 @@ void VPlanTransforms::prepareForVectorization(
501501 cast<VPBasicBlock>(HeaderVPB),
502502 cast<VPBasicBlock>(LatchVPB), Range);
503503 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+ }
504509 }
505-
506510 cast<VPBasicBlock>(Pred)->getTerminator ()->eraseFromParent ();
507511 VPBlockUtils::disconnectBlocks (Pred, EB);
508512 }
@@ -535,45 +539,33 @@ void VPlanTransforms::prepareForVectorization(
535539 // Thus if tail is to be folded, we know we don't need to run the
536540 // remainder and we can set the condition to true.
537541 // 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.
557542 VPBlockUtils::connectBlocks (MiddleVPBB, ScalarPH);
558543 // Also connect the entry block to the scalar preheader.
559544 // TODO: Also introduce a branch recipe together with the minimum trip count
560545 // check.
561546 VPBlockUtils::connectBlocks (Plan.getEntry (), ScalarPH);
562547 Plan.getEntry ()->swapSuccessors ();
563548
549+ if (MiddleVPBB->getNumSuccessors () != 2 )
550+ return ;
551+
564552 auto *ScalarLatchTerm = TheLoop->getLoopLatch ()->getTerminator ();
565553 // Here we use the same DebugLoc as the scalar loop latch terminator instead
566554 // of the corresponding compare because they may have ended up with
567555 // different line numbers and we want to avoid awkward line stepping while
568556 // debugging. Eg. if the compare has got a line number inside the loop.
569557 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" );
577569 Builder.createNaryOp (VPInstruction::BranchOnCond, {Cmp},
578570 ScalarLatchTerm->getDebugLoc ());
579571}
0 commit comments