Skip to content

Commit 1836f61

Browse files
committed
Opt: Remove dependency on VPWidenIntOrFpInductionRecipe and expend VPVectorPointerRecipe
1 parent 4ccf78c commit 1836f61

File tree

7 files changed

+395
-228
lines changed

7 files changed

+395
-228
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,9 +3627,9 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
36273627
if (IsUniformMemOpUse(I))
36283628
return true;
36293629

3630-
return (WideningDecision == CM_Widen ||
3631-
WideningDecision == CM_Widen_Reverse ||
3632-
WideningDecision == CM_Interleave);
3630+
return (
3631+
WideningDecision == CM_Widen || WideningDecision == CM_Widen_Reverse ||
3632+
WideningDecision == CM_Strided || WideningDecision == CM_Interleave);
36333633
};
36343634

36353635
// Returns true if Ptr is the pointer operand of a memory access instruction
@@ -8367,17 +8367,27 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
83678367
// reverse consecutive.
83688368
LoopVectorizationCostModel::InstWidening Decision =
83698369
CM.getWideningDecision(I, Range.Start);
8370+
8371+
auto SameWiden = [&](ElementCount VF) -> bool {
8372+
return Decision == CM.getWideningDecision(I, VF);
8373+
};
8374+
bool ContainsWidenVF =
8375+
LoopVectorizationPlanner::getDecisionAndClampRange(SameWiden, Range);
8376+
assert(ContainsWidenVF &&
8377+
"At least widen the memory accesses by the Start VF.");
8378+
83708379
bool Reverse = Decision == LoopVectorizationCostModel::CM_Widen_Reverse;
83718380
bool Consecutive =
83728381
Reverse || Decision == LoopVectorizationCostModel::CM_Widen;
83738382
bool Strided = Decision == LoopVectorizationCostModel::CM_Strided;
83748383

83758384
VPValue *Ptr = isa<LoadInst>(I) ? Operands[0] : Operands[1];
8376-
if (Consecutive) {
8385+
if (Consecutive || Strided) {
83778386
auto *GEP = dyn_cast<GetElementPtrInst>(
83788387
Ptr->getUnderlyingValue()->stripPointerCasts());
83798388
VPSingleDefRecipe *VectorPtr;
83808389
if (Reverse) {
8390+
assert(!Strided && "Reverse and Strided are mutually exclusive.");
83818391
// When folding the tail, we may compute an address that we don't in the
83828392
// original scalar loop and it may not be inbounds. Drop Inbounds in that
83838393
// case.
@@ -8388,7 +8398,7 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
83888398
VectorPtr = new VPReverseVectorPointerRecipe(
83898399
Ptr, &Plan.getVF(), getLoadStoreType(I), Flags, I->getDebugLoc());
83908400
} else {
8391-
VectorPtr = new VPVectorPointerRecipe(Ptr, getLoadStoreType(I),
8401+
VectorPtr = new VPVectorPointerRecipe(Ptr, getLoadStoreType(I), Strided,
83928402
GEP ? GEP->getNoWrapFlags()
83938403
: GEPNoWrapFlags::none(),
83948404
I->getDebugLoc());

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,12 +1568,15 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
15681568
public VPUnrollPartAccessor<1> {
15691569
Type *IndexedTy;
15701570

1571+
/// Indicate whether to compute the pointer for strided memory accesses.
1572+
bool Strided;
1573+
15711574
public:
1572-
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags,
1573-
DebugLoc DL)
1575+
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, bool Strided,
1576+
GEPNoWrapFlags GEPFlags, DebugLoc DL)
15741577
: VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
15751578
GEPFlags, DL),
1576-
IndexedTy(IndexedTy) {}
1579+
IndexedTy(IndexedTy), Strided(Strided) {}
15771580

15781581
VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
15791582

@@ -1594,7 +1597,7 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
15941597
}
15951598

15961599
VPVectorPointerRecipe *clone() override {
1597-
return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1600+
return new VPVectorPointerRecipe(getOperand(0), IndexedTy, Strided,
15981601
getGEPNoWrapFlags(), getDebugLoc());
15991602
}
16001603

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,9 @@ void VPVectorPointerRecipe::execute(VPTransformState &State) {
21152115
CurrentPart, Builder);
21162116
Value *Ptr = State.get(getOperand(0), VPLane(0));
21172117

2118-
Value *Increment = createStepForVF(Builder, IndexTy, State.VF, CurrentPart);
2118+
// TODO: Support non-unit-reverse strided accesses.
2119+
int64_t Step = Strided ? -1 * CurrentPart : CurrentPart;
2120+
Value *Increment = createStepForVF(Builder, IndexTy, State.VF, Step);
21192121
Value *ResultPtr =
21202122
Builder.CreateGEP(IndexedTy, Ptr, Increment, "", getGEPNoWrapFlags());
21212123

0 commit comments

Comments
 (0)