Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3666,7 +3666,7 @@ PSE.getSE()->forgetLoop(OrigLoop); VPBasicBlock *LatchVPBB = Plan.getVectorLoopRegion()->getExitingBasicBlock(); - Loop *VectorLoop = LI->getLoopFor(State.CFG.VPBB2IRBB[LatchVPBB]); + Loop *VectorLoop = LI->getLoopFor(State.CFG.VPBB2IRBB[LatchVPBB].back()); if (Cost->requiresScalarEpilogue(VF)) { // No edge from the middle block to the unique exit block has been inserted // and there is nothing to fix from vector loop; phis should have incoming @@ -3877,7 +3877,7 @@ VPBasicBlock *LatchVPBB = PhiR->getParent()->getEnclosingLoopRegion()->getExitingBasicBlock(); - BasicBlock *VectorLoopLatch = State.CFG.VPBB2IRBB[LatchVPBB]; + BasicBlock *VectorLoopLatch = State.CFG.VPBB2IRBB[LatchVPBB].back(); // If tail is folded by masking, the vector value to leave the loop should be // a Select choosing between the vectorized LoopExitInst and vectorized Phi, // instead of the former. For an inloop reduction the reduction will already @@ -4165,7 +4165,7 @@ for (unsigned i = 0; i < VPPhi->getNumOperands(); ++i) { VPValue *Inc = VPPhi->getIncomingValue(i); VPBasicBlock *VPBB = VPPhi->getIncomingBlock(i); - NewPhi->addIncoming(State.get(Inc, 0), State.CFG.VPBB2IRBB[VPBB]); + NewPhi->addIncoming(State.get(Inc, 0), State.CFG.VPBB2IRBB[VPBB].back()); } } } @@ -7618,7 +7618,7 @@ VPBasicBlock *HeaderVPBB = BestVPlan.getVectorLoopRegion()->getEntryBasicBlock(); - Loop *L = LI->getLoopFor(State.CFG.VPBB2IRBB[HeaderVPBB]); + Loop *L = LI->getLoopFor(State.CFG.VPBB2IRBB[HeaderVPBB].back()); if (VectorizedLoopID) L->setLoopID(VectorizedLoopID.value()); else { Index: llvm/lib/Transforms/Vectorize/VPlan.h =================================================================== --- llvm/lib/Transforms/Vectorize/VPlan.h +++ llvm/lib/Transforms/Vectorize/VPlan.h @@ -334,9 +334,8 @@ /// vector loop. BasicBlock *ExitBB = nullptr; - /// A mapping of each VPBasicBlock to the corresponding BasicBlock. In case - /// of replication, maps the BasicBlock of the last replica created. - SmallDenseMap VPBB2IRBB; + /// A mapping of each VPBasicBlock to the corresponding BasicBlocks. + SmallDenseMap > VPBB2IRBB; CFGState() = default; Index: llvm/lib/Transforms/Vectorize/VPlan.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/VPlan.cpp +++ llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -224,7 +224,7 @@ } BasicBlock *VPTransformState::CFGState::getPreheaderBBFor(VPRecipeBase *R) { VPRegionBlock *LoopRegion = R->getParent()->getEnclosingLoopRegion(); - return VPBB2IRBB[LoopRegion->getPreheaderVPBB()]; + return VPBB2IRBB[LoopRegion->getPreheaderVPBB()].back(); } void VPTransformState::addNewMetadata(Instruction *To, @@ -284,7 +284,7 @@ for (VPBlockBase *PredVPBlock : getHierarchicalPredecessors()) { VPBasicBlock *PredVPBB = PredVPBlock->getExitingBasicBlock(); auto &PredVPSuccessors = PredVPBB->getHierarchicalSuccessors(); - BasicBlock *PredBB = CFG.VPBB2IRBB[PredVPBB]; + BasicBlock *PredBB = CFG.VPBB2IRBB[PredVPBB].back(); assert(PredBB && "Predecessor basic-block not found building successor."); auto *PredBBTerminator = PredBB->getTerminator(); @@ -334,7 +334,7 @@ VPBasicBlock *ExitingVPBB = PredVPB->getExitingBasicBlock(); assert(PredVPB->getSingleSuccessor() == this && "predecessor must have the current block as only successor"); - BasicBlock *ExitingBB = State->CFG.VPBB2IRBB[ExitingVPBB]; + BasicBlock *ExitingBB = State->CFG.VPBB2IRBB[ExitingVPBB].back(); // The Exit block of a loop is always set to be successor 0 of the Exiting // block. cast(ExitingBB->getTerminator())->setSuccessor(0, NewBB); @@ -370,7 +370,7 @@ LLVM_DEBUG(dbgs() << "LV: vectorizing VPBB:" << getName() << " in BB:" << NewBB->getName() << '\n'); - State->CFG.VPBB2IRBB[this] = NewBB; + State->CFG.VPBB2IRBB[this].push_back(NewBB); State->CFG.PrevVPBB = this; for (VPRecipeBase &Recipe : Recipes) @@ -510,7 +510,7 @@ // Create and register the new vector loop. Loop *PrevLoop = State->CurrentVectorLoop; State->CurrentVectorLoop = State->LI->AllocateLoop(); - BasicBlock *VectorPH = State->CFG.VPBB2IRBB[getPreheaderVPBB()]; + BasicBlock *VectorPH = State->CFG.VPBB2IRBB[getPreheaderVPBB()].back(); Loop *ParentLoop = State->LI->getLoopFor(VectorPH); // Insert the new loop into the loop nest and register the new basic blocks @@ -679,7 +679,7 @@ Block->execute(State); VPBasicBlock *LatchVPBB = getVectorLoopRegion()->getExitingBasicBlock(); - BasicBlock *VectorLatchBB = State->CFG.VPBB2IRBB[LatchVPBB]; + BasicBlock *VectorLatchBB = State->CFG.VPBB2IRBB[LatchVPBB].back(); // Fix the latch value of canonical, reduction and first-order recurrences // phis in the vector loop. @@ -735,7 +735,7 @@ // We do not attempt to preserve DT for outer loop vectorization currently. if (!EnableVPlanNativePath) { - BasicBlock *VectorHeaderBB = State->CFG.VPBB2IRBB[Header]; + BasicBlock *VectorHeaderBB = State->CFG.VPBB2IRBB[Header].front(); State->DT->addNewBlock(VectorHeaderBB, VectorPreHeader); updateDominatorTree(State->DT, VectorHeaderBB, VectorLatchBB, State->CFG.ExitBB); Index: llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -311,7 +311,7 @@ Builder.CreateCondBr(Cond, Builder.GetInsertBlock(), nullptr); if (getParent()->isExiting()) - CondBr->setSuccessor(1, State.CFG.VPBB2IRBB[Header]); + CondBr->setSuccessor(1, State.CFG.VPBB2IRBB[Header].front()); CondBr->setSuccessor(0, nullptr); Builder.GetInsertBlock()->getTerminator()->eraseFromParent(); @@ -336,7 +336,7 @@ // Note that CreateCondBr expects a valid BB as first argument, so we need // to set it to nullptr later. BranchInst *CondBr = Builder.CreateCondBr(Cond, Builder.GetInsertBlock(), - State.CFG.VPBB2IRBB[Header]); + State.CFG.VPBB2IRBB[Header].front()); CondBr->setSuccessor(0, nullptr); Builder.GetInsertBlock()->getTerminator()->eraseFromParent(); break;