@@ -1023,10 +1023,8 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10231023 if (match (&R, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue (X),
10241024 m_SpecificInt (1 )))) {
10251025 Type *WideStepTy = TypeInfo.inferScalarType (R.getVPSingleValue ());
1026- if (TypeInfo.inferScalarType (X) != WideStepTy) {
1027- X = new VPWidenCastRecipe (Instruction::Trunc, X, WideStepTy);
1028- X->getDefiningRecipe ()->insertBefore (&R);
1029- }
1026+ if (TypeInfo.inferScalarType (X) != WideStepTy)
1027+ X = VPBuilder (&R).createWidenCast (Instruction::Trunc, X, WideStepTy);
10301028 R.getVPSingleValue ()->replaceAllUsesWith (X);
10311029 }
10321030}
@@ -2381,6 +2379,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
23812379 VPTypeAnalysis &TypeInfo) {
23822380 using namespace llvm ::VPlanPatternMatch;
23832381
2382+ SmallVector<VPRecipeBase *> ToRemove;
23842383 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
23852384 vp_depth_first_deep (Plan.getEntry ()))) {
23862385 for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
@@ -2393,7 +2392,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
23932392 PhiR->getDebugLoc (), Name);
23942393 ScalarR->insertBefore (PhiR);
23952394 PhiR->replaceAllUsesWith (ScalarR);
2396- PhiR-> eraseFromParent ( );
2395+ ToRemove. push_back (PhiR );
23972396 continue ;
23982397 }
23992398
@@ -2402,8 +2401,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24022401 if (!match (&R, m_VPInstruction<VPInstruction::WideIVStep>(
24032402 m_VPValue (VectorStep), m_VPValue (ScalarStep))))
24042403 continue ;
2404+
2405+ // Expand WideIVStep.
24052406 auto *VPI = cast<VPInstruction>(&R);
2406- VPBuilder Builder (VPI-> getParent (), VPI-> getIterator () );
2407+ VPBuilder Builder (VPI);
24072408 Type *IVTy = TypeInfo.inferScalarType (VPI);
24082409 if (TypeInfo.inferScalarType (VectorStep) != IVTy) {
24092410 Instruction::CastOps CastOp = IVTy->isFloatingPointTy ()
@@ -2432,9 +2433,12 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24322433 MulOpc, {VectorStep, ScalarStep}, FMFs, R.getDebugLoc ());
24332434 VectorStep = Mul;
24342435 VPI->replaceAllUsesWith (VectorStep);
2435- VPI-> eraseFromParent ( );
2436+ ToRemove. push_back (VPI );
24362437 }
24372438 }
2439+
2440+ for (VPRecipeBase *R : ToRemove)
2441+ R->eraseFromParent ();
24382442}
24392443
24402444void VPlanTransforms::handleUncountableEarlyExit (
0 commit comments