@@ -2573,7 +2573,7 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) {
25732573 // Remove redundant induction instructions.
25742574 cse (HeaderBB);
25752575
2576- if (Plan.getScalarPreheader ()->hasPredecessors ())
2576+ if (! Plan.getScalarPreheader ()->hasPredecessors ())
25772577 return ;
25782578
25792579 // Set/update profile weights for the vector and remainder loops as original
@@ -7230,7 +7230,13 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
72307230 VPlanTransforms::removeBranchOnConst (BestVPlan);
72317231 if (BestVPlan.getEntry ()->getSingleSuccessor () ==
72327232 BestVPlan.getScalarPreheader ()) {
7233- // TODO: Should not even try to vectorize.
7233+ // TODO: The vector loop would be dead, should not even try to vectorize.
7234+ ORE->emit ([&]() {
7235+ return OptimizationRemarkAnalysis (DEBUG_TYPE, " VectorizationDead" ,
7236+ OrigLoop->getStartLoc (),
7237+ OrigLoop->getHeader ())
7238+ << " Created vector loop never executes." ;
7239+ });
72347240 return DenseMap<const SCEV *, Value *>();
72357241 }
72367242
@@ -7315,6 +7321,10 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73157321 if (BasicBlock *SCEVCheckBlock = ILV.RTChecks .getSCEVChecks ().second )
73167322 SCEVCheckBlock->moveAfter (EntryBB);
73177323
7324+ std::optional<MDNode *> VectorizedLoopID = makeFollowupLoopID (
7325+ OrigLoop->getLoopID (),
7326+ {LLVMLoopVectorizeFollowupAll, LLVMLoopVectorizeFollowupVectorized});
7327+
73187328 BestVPlan.execute (&State);
73197329
73207330 // 2.5 When vectorizing the epilogue, fix reduction resume values from the
@@ -7347,21 +7357,16 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73477357 // replace the vectorizer-specific hints below).
73487358 VPBasicBlock *HeaderVPBB = vputils::getFirstLoopHeader (BestVPlan, State.VPDT );
73497359 if (HeaderVPBB) {
7350- MDNode *OrigLoopID = OrigLoop->getLoopID ();
7351-
7352- std::optional<MDNode *> VectorizedLoopID =
7353- makeFollowupLoopID (OrigLoopID, {LLVMLoopVectorizeFollowupAll,
7354- LLVMLoopVectorizeFollowupVectorized});
7355-
73567360 Loop *L = LI->getLoopFor (State.CFG .VPBB2IRBB [HeaderVPBB]);
73577361 if (VectorizedLoopID) {
73587362 L->setLoopID (*VectorizedLoopID);
73597363 } else {
73607364 // Keep all loop hints from the original loop on the vector loop (we'll
73617365 // replace the vectorizer-specific hints below).
7362- if (BestVPlan.getScalarPreheader ()->getNumPredecessors () > 0 )
7366+ if (BestVPlan.getScalarPreheader ()->hasPredecessors ()) {
73637367 if (MDNode *LID = OrigLoop->getLoopID ())
73647368 L->setLoopID (LID);
7369+ }
73657370
73667371 LoopVectorizeHints Hints (L, true , *ORE);
73677372 Hints.setAlreadyVectorized ();
@@ -7392,16 +7397,6 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
73927397 addRuntimeUnrollDisableMetaData (L);
73937398 }
73947399
7395- if (BestVPlan.getScalarPreheader ()->getNumPredecessors () == 0 ) {
7396- // If the original loop became unreachable, we need to delete it.
7397- auto Blocks = OrigLoop->getBlocksVector ();
7398- Blocks.push_back (cast<VPIRBasicBlock>(BestVPlan.getScalarPreheader ())
7399- ->getIRBasicBlock ());
7400- for (auto *BB : Blocks)
7401- LI->removeBlock (BB);
7402- LI->erase (OrigLoop);
7403- }
7404-
74057400 // 3. Fix the vectorized code: take care of header phi's, live-outs,
74067401 // predication, updating analyses.
74077402 ILV.fixVectorizedLoop (State);
@@ -10322,7 +10317,9 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1032210317
1032310318 assert (DT->verify (DominatorTree::VerificationLevel::Fast) &&
1032410319 " DT not preserved correctly" );
10320+ assert (!verifyFunction (*F, &dbgs ()));
1032510321
10322+ // The original loop has been removed, no need to update its metadata.
1032610323 if (LoopRemoved)
1032710324 return true ;
1032810325
@@ -10339,7 +10336,6 @@ bool LoopVectorizePass::processLoop(Loop *L) {
1033910336 Hints.setAlreadyVectorized ();
1034010337 }
1034110338
10342- assert (!verifyFunction (*L->getHeader ()->getParent (), &dbgs ()));
1034310339 return true ;
1034410340}
1034510341
0 commit comments