@@ -527,13 +527,12 @@ static VPScalarIVStepsRecipe *
527
527
createScalarIVSteps (VPlan &Plan, InductionDescriptor::InductionKind Kind,
528
528
Instruction::BinaryOps InductionOpcode,
529
529
FPMathOperator *FPBinOp, Instruction *TruncI,
530
- VPValue *StartV, VPValue *Step, VPBasicBlock::iterator IP ) {
530
+ VPValue *StartV, VPValue *Step, VPBuilder &Builder ) {
531
531
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion ()->getEntryBasicBlock ();
532
532
VPCanonicalIVPHIRecipe *CanonicalIV = Plan.getCanonicalIV ();
533
533
VPSingleDefRecipe *BaseIV = CanonicalIV;
534
534
if (!CanonicalIV->isCanonical (Kind, StartV, Step)) {
535
- BaseIV = new VPDerivedIVRecipe (Kind, FPBinOp, StartV, CanonicalIV, Step);
536
- HeaderVPBB->insert (BaseIV, IP);
535
+ BaseIV = Builder.createDerivedIV (Kind, FPBinOp, StartV, CanonicalIV, Step);
537
536
}
538
537
539
538
// Truncate base induction if needed.
@@ -545,8 +544,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
545
544
assert (ResultTy->getScalarSizeInBits () > TruncTy->getScalarSizeInBits () &&
546
545
" Not truncating." );
547
546
assert (ResultTy->isIntegerTy () && " Truncation requires an integer type" );
548
- BaseIV = new VPScalarCastRecipe (Instruction::Trunc, BaseIV, TruncTy);
549
- HeaderVPBB->insert (BaseIV, IP);
547
+ BaseIV = Builder.createScalarCast (Instruction::Trunc, BaseIV, TruncTy);
550
548
ResultTy = TruncTy;
551
549
}
552
550
@@ -556,17 +554,13 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
556
554
assert (StepTy->getScalarSizeInBits () > ResultTy->getScalarSizeInBits () &&
557
555
" Not truncating." );
558
556
assert (StepTy->isIntegerTy () && " Truncation requires an integer type" );
559
- Step = new VPScalarCastRecipe (Instruction::Trunc, Step, ResultTy);
560
557
auto *VecPreheader =
561
558
cast<VPBasicBlock>(HeaderVPBB->getSingleHierarchicalPredecessor ());
562
- VecPreheader->appendRecipe (Step->getDefiningRecipe ());
559
+ VPBuilder::InsertPointGuard Guard (Builder);
560
+ Builder.setInsertPoint (VecPreheader);
561
+ Step = Builder.createScalarCast (Instruction::Trunc, Step, ResultTy);
563
562
}
564
-
565
- VPScalarIVStepsRecipe *Steps = new VPScalarIVStepsRecipe (
566
- BaseIV, Step, InductionOpcode,
567
- FPBinOp ? FPBinOp->getFastMathFlags () : FastMathFlags ());
568
- HeaderVPBB->insert (Steps, IP);
569
- return Steps;
563
+ return Builder.createScalarIVSteps (InductionOpcode, FPBinOp, BaseIV, Step);
570
564
}
571
565
572
566
// / Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd
@@ -582,7 +576,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
582
576
SmallVector<VPRecipeBase *> ToRemove;
583
577
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion ()->getEntryBasicBlock ();
584
578
bool HasOnlyVectorVFs = !Plan.hasVF (ElementCount::getFixed (1 ));
585
- VPBasicBlock::iterator InsertPt = HeaderVPBB->getFirstNonPhi ();
579
+ VPBuilder Builder (HeaderVPBB, HeaderVPBB->getFirstNonPhi () );
586
580
for (VPRecipeBase &Phi : HeaderVPBB->phis ()) {
587
581
// Replace wide pointer inductions which have only their scalars used by
588
582
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
@@ -596,7 +590,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
596
590
VPValue *StepV = PtrIV->getOperand (1 );
597
591
VPScalarIVStepsRecipe *Steps = createScalarIVSteps (
598
592
Plan, InductionDescriptor::IK_IntInduction, Instruction::Add, nullptr ,
599
- nullptr , StartV, StepV, InsertPt );
593
+ nullptr , StartV, StepV, Builder );
600
594
601
595
auto *Recipe = new VPInstruction (VPInstruction::PtrAdd,
602
596
{PtrIV->getStartValue (), Steps},
@@ -622,7 +616,7 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
622
616
Plan, ID.getKind (), ID.getInductionOpcode (),
623
617
dyn_cast_or_null<FPMathOperator>(ID.getInductionBinOp ()),
624
618
WideIV->getTruncInst (), WideIV->getStartValue (), WideIV->getStepValue (),
625
- InsertPt );
619
+ Builder );
626
620
627
621
// Update scalar users of IV to use Step instead.
628
622
if (!HasOnlyVectorVFs)
0 commit comments