[VPlan] Move SCEV expansion for pointer induction to VPExpandSCEV (NFC).
Use VPExpandSCEVRecipe to expand the step of pointer inductions. This cleanup addresses a corresponding FIXME. It should be NFC, as steps for pointer induction must be constants, which makes expansion trivial.
This commit is contained in:
2 files changed
+14
-17
No files matched your search
@@ -8197,9 +8197,12 @@ VPRecipeBase *VPRecipeBuilder::tryToOptimizeInductionPHI(
|
||||
*PSE.getSE(), *OrigLoop, Range);
|
||||
|
||||
// Check if this is pointer induction. If so, build the recipe for it.
|
||||
if (auto *II = Legal->getPointerInductionDescriptor(Phi))
|
||||
return new VPWidenPointerInductionRecipe(Phi, Operands[0], *II,
|
||||
*PSE.getSE());
|
||||
if (auto *II = Legal->getPointerInductionDescriptor(Phi)) {
|
||||
VPValue *Step = vputils::getOrCreateVPValueForSCEVExpr(Plan, II->getStep(),
|
||||
*PSE.getSE());
|
||||
assert(isa<SCEVConstant>(II->getStep()));
|
||||
return new VPWidenPointerInductionRecipe(Phi, Operands[0], Step, *II);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -9437,8 +9440,7 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
|
||||
PartStart, ConstantInt::get(PtrInd->getType(), Lane));
|
||||
Value *GlobalIdx = State.Builder.CreateAdd(PtrInd, Idx);
|
||||
|
||||
Value *Step = CreateStepValue(IndDesc.getStep(), SE,
|
||||
State.CFG.PrevBB->getTerminator());
|
||||
Value *Step = State.get(getOperand(1), VPIteration(0, Part));
|
||||
Value *SclrGep = emitTransformedIndex(
|
||||
State.Builder, GlobalIdx, IndDesc.getStartValue(), Step, IndDesc);
|
||||
SclrGep->setName("next.gep");
|
||||
@@ -9465,9 +9467,7 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
|
||||
const DataLayout &DL = NewPointerPhi->getModule()->getDataLayout();
|
||||
Instruction *InductionLoc = &*State.Builder.GetInsertPoint();
|
||||
|
||||
const SCEV *ScalarStep = IndDesc.getStep();
|
||||
SCEVExpander Exp(SE, DL, "induction");
|
||||
Value *ScalarStepValue = Exp.expandCodeFor(ScalarStep, PhiType, InductionLoc);
|
||||
Value *ScalarStepValue = State.get(getOperand(1), VPIteration(0, 0));
|
||||
Value *RuntimeVF = getRuntimeVF(State.Builder, PhiType, State.VF);
|
||||
Value *NumUnrolledElems =
|
||||
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, State.UF));
|
||||
@@ -9495,6 +9495,8 @@ void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
|
||||
StartOffset = State.Builder.CreateAdd(
|
||||
StartOffset, State.Builder.CreateStepVector(VecPhiType));
|
||||
|
||||
assert(ScalarStepValue == State.get(getOperand(1), VPIteration(0, Part)) &&
|
||||
"scalar step must be the same across all parts");
|
||||
Value *GEP = State.Builder.CreateGEP(
|
||||
IndDesc.getElementType(), NewPointerPhi,
|
||||
State.Builder.CreateMul(
|
||||
|
||||
@@ -1183,21 +1183,16 @@ public:
|
||||
class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe {
|
||||
const InductionDescriptor &IndDesc;
|
||||
|
||||
/// SCEV used to expand step.
|
||||
/// FIXME: move expansion of step to the pre-header, once it is modeled
|
||||
/// explicitly.
|
||||
ScalarEvolution &SE;
|
||||
|
||||
public:
|
||||
/// Create a new VPWidenPointerInductionRecipe for \p Phi with start value \p
|
||||
/// Start.
|
||||
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start,
|
||||
const InductionDescriptor &IndDesc,
|
||||
ScalarEvolution &SE)
|
||||
VPWidenPointerInductionRecipe(PHINode *Phi, VPValue *Start, VPValue *Step,
|
||||
const InductionDescriptor &IndDesc)
|
||||
: VPHeaderPHIRecipe(VPVWidenPointerInductionSC, VPWidenPointerInductionSC,
|
||||
Phi),
|
||||
IndDesc(IndDesc), SE(SE) {
|
||||
IndDesc(IndDesc) {
|
||||
addOperand(Start);
|
||||
addOperand(Step);
|
||||
}
|
||||
|
||||
~VPWidenPointerInductionRecipe() override = default;
|
||||
|
||||
Reference in new issue
Block a user