Skip to content

Commit a2b8a93

Browse files
authored
[VPlan] Pass NumUnrolledElems as operand to VPWidenPointerInductionRecipe. NFC (#119859)
Similarly to VPWidenIntOrFpInductionRecipe, if we want to support it in EVL tail folding we need to increment the induction by EVL steps instead of VF*UF steps, but currently this is hard-wired in VPWidenPointerInductionRecipe. This adds an operand for the number of elements unrolled and plumbs it through, so that we can swap it out in VPlanTransforms::tryAddExplicitVectorLength further down the line.
1 parent 96ab74b commit a2b8a93

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7826,7 +7826,7 @@ VPHeaderPHIRecipe *VPRecipeBuilder::tryToOptimizeInductionPHI(
78267826
VPValue *Step = vputils::getOrCreateVPValueForSCEVExpr(Plan, II->getStep(),
78277827
*PSE.getSE());
78287828
return new VPWidenPointerInductionRecipe(
7829-
Phi, Operands[0], Step, *II,
7829+
Phi, Operands[0], Step, &Plan.getVFxUF(), *II,
78307830
LoopVectorizationPlanner::getDecisionAndClampRange(
78317831
[&](ElementCount VF) {
78327832
return CM.isScalarAfterVectorization(Phi, VF);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,25 +2034,30 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
20342034
};
20352035

20362036
class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe,
2037-
public VPUnrollPartAccessor<3> {
2037+
public VPUnrollPartAccessor<4> {
20382038
bool IsScalarAfterVectorization;
20392039

20402040
public:
20412041
/// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
2042-
/// Start.
2042+
/// Start and the number of elements unrolled \p NumUnrolledElems, typically
2043+
/// VF*UF.
20432044
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step,
2045+
VPValue *NumUnrolledElems,
20442046
const InductionDescriptor &IndDesc,
20452047
bool IsScalarAfterVectorization, DebugLoc DL)
20462048
: VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
20472049
Step, IndDesc, DL),
2048-
IsScalarAfterVectorization(IsScalarAfterVectorization) {}
2050+
IsScalarAfterVectorization(IsScalarAfterVectorization) {
2051+
addOperand(NumUnrolledElems);
2052+
}
20492053

20502054
~VPWidenPointerInductionRecipe() override = default;
20512055

20522056
VPWidenPointerInductionRecipe *clone() override {
20532057
return new VPWidenPointerInductionRecipe(
20542058
cast<PHINode>(getUnderlyingInstr()), getOperand(0), getOperand(1),
2055-
getInductionDescriptor(), IsScalarAfterVectorization, getDebugLoc());
2059+
getOperand(2), getInductionDescriptor(), IsScalarAfterVectorization,
2060+
getDebugLoc());
20562061
}
20572062

20582063
VP_CLASSOF_IMPL(VPDef::VPWidenPointerInductionSC)
@@ -2067,7 +2072,7 @@ class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe,
20672072
/// the first unrolled part, if it exists. Returns itself if unrolling did not
20682073
/// take place.
20692074
VPValue *getFirstUnrolledPartOperand() {
2070-
return getUnrollPart(*this) == 0 ? this : getOperand(2);
2075+
return getUnrollPart(*this) == 0 ? this : getOperand(3);
20712076
}
20722077

20732078
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,8 +3544,7 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
35443544
if (CurrentPart == 0) {
35453545
// The recipe represents the first part of the pointer induction. Create the
35463546
// GEP to increment the phi across all unrolled parts.
3547-
Value *NumUnrolledElems =
3548-
State.get(&getParent()->getPlan()->getVFxUF(), true);
3547+
Value *NumUnrolledElems = State.get(getOperand(2), true);
35493548

35503549
Value *InductionGEP = GetElementPtrInst::Create(
35513550
State.Builder.getInt8Ty(), NewPointerPhi,
@@ -3581,19 +3580,21 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
35813580
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
35823581
void VPWidenPointerInductionRecipe::print(raw_ostream &O, const Twine &Indent,
35833582
VPSlotTracker &SlotTracker) const {
3584-
assert((getNumOperands() == 2 || getNumOperands() == 4) &&
3583+
assert((getNumOperands() == 3 || getNumOperands() == 5) &&
35853584
"unexpected number of operands");
35863585
O << Indent << "EMIT ";
35873586
printAsOperand(O, SlotTracker);
35883587
O << " = WIDEN-POINTER-INDUCTION ";
35893588
getStartValue()->printAsOperand(O, SlotTracker);
35903589
O << ", ";
35913590
getStepValue()->printAsOperand(O, SlotTracker);
3592-
if (getNumOperands() == 4) {
3593-
O << ", ";
3594-
getOperand(2)->printAsOperand(O, SlotTracker);
3591+
O << ", ";
3592+
getOperand(2)->printAsOperand(O, SlotTracker);
3593+
if (getNumOperands() == 5) {
35953594
O << ", ";
35963595
getOperand(3)->printAsOperand(O, SlotTracker);
3596+
O << ", ";
3597+
getOperand(4)->printAsOperand(O, SlotTracker);
35973598
}
35983599
}
35993600
#endif

0 commit comments

Comments
 (0)