@@ -511,22 +511,25 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
511511 for (unsigned I = 0 ; I != VF.getKnownMinValue (); ++I)
512512 LaneDefs.push_back (cloneForLane (Plan, Builder, IdxTy, RepR, VPLane (I)));
513513
514+ if (RepR->getNumUsers () == 0 ) {
515+ RepR->eraseFromParent ();
516+ continue ;
517+ }
518+
514519 // / Users that only demand the first lane can use the definition for lane
515520 // / 0.
516521 RepR->replaceUsesWithIf (LaneDefs[0 ], [RepR](VPUser &U, unsigned ) {
517522 return U.onlyFirstLaneUsed (RepR);
518523 });
519524
520- Type *ResTy = RepR->getUnderlyingInstr ()->getType ();
521525 // If needed, create a Build(Struct)Vector recipe to insert the scalar
522526 // lane values into a vector.
523- if (!ResTy->isVoidTy ()) {
524- VPValue *VecRes = Builder.createNaryOp (
525- ResTy->isStructTy () ? VPInstruction::BuildStructVector
526- : VPInstruction::BuildVector,
527- LaneDefs);
528- RepR->replaceAllUsesWith (VecRes);
529- }
527+ Type *ResTy = RepR->getUnderlyingInstr ()->getType ();
528+ VPValue *VecRes = Builder.createNaryOp (
529+ ResTy->isStructTy () ? VPInstruction::BuildStructVector
530+ : VPInstruction::BuildVector,
531+ LaneDefs);
532+ RepR->replaceAllUsesWith (VecRes);
530533 RepR->eraseFromParent ();
531534 }
532535 }
0 commit comments