Skip to content

Commit 35ee6de

Browse files
committed
[VPlan] Simplify addCanonicalIVRecipes by using VPBuilder (NFC).
Use VPBuilder to construct VPInstructions, which means there's no need to manually inserting recipes.
1 parent 715567d commit 35ee6de

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8510,21 +8510,16 @@ static void addCanonicalIVRecipes(VPlan &Plan, Type *IdxTy, bool HasNUW,
85108510
VPBasicBlock *Header = TopRegion->getEntryBasicBlock();
85118511
Header->insert(CanonicalIVPHI, Header->begin());
85128512

8513-
// Add a CanonicalIVIncrement{NUW} VPInstruction to increment the scalar
8514-
// IV by VF * UF.
8515-
auto *CanonicalIVIncrement =
8516-
new VPInstruction(Instruction::Add, {CanonicalIVPHI, &Plan.getVFxUF()},
8517-
{HasNUW, false}, DL, "index.next");
8513+
VPBuilder Builder(TopRegion->getExitingBasicBlock());
8514+
// Add a VPInstruction to increment the scalar canonical IV by VF * UF.
8515+
auto *CanonicalIVIncrement = Builder.createOverflowingOp(
8516+
Instruction::Add, {CanonicalIVPHI, &Plan.getVFxUF()}, {HasNUW, false}, DL,
8517+
"index.next");
85188518
CanonicalIVPHI->addOperand(CanonicalIVIncrement);
85198519

8520-
VPBasicBlock *EB = TopRegion->getExitingBasicBlock();
8521-
EB->appendRecipe(CanonicalIVIncrement);
8522-
85238520
// Add the BranchOnCount VPInstruction to the latch.
8524-
VPInstruction *BranchBack =
8525-
new VPInstruction(VPInstruction::BranchOnCount,
8526-
{CanonicalIVIncrement, &Plan.getVectorTripCount()}, DL);
8527-
EB->appendRecipe(BranchBack);
8521+
Builder.createNaryOp(VPInstruction::BranchOnCount,
8522+
{CanonicalIVIncrement, &Plan.getVectorTripCount()}, DL);
85288523
}
85298524

85308525
// Add exit values to \p Plan. VPLiveOuts are added for each LCSSA phi in the

0 commit comments

Comments
 (0)