Skip to content

Commit 987f3f6

Browse files
committed
Opt: Remove dependency on VPWidenIntOrFpInductionRecipe and expend VPVectorPointerRecipe
1 parent 431f892 commit 987f3f6

File tree

6 files changed

+119
-161
lines changed

6 files changed

+119
-161
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

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

3624-
return (WideningDecision == CM_Widen ||
3625-
WideningDecision == CM_Widen_Reverse ||
3626-
WideningDecision == CM_Interleave);
3624+
return (
3625+
WideningDecision == CM_Widen || WideningDecision == CM_Widen_Reverse ||
3626+
WideningDecision == CM_Strided || WideningDecision == CM_Interleave);
36273627
};
36283628

36293629
// 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
@@ -1571,12 +1571,15 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
15711571
public VPUnrollPartAccessor<1> {
15721572
Type *IndexedTy;
15731573

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

15811584
VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
15821585

@@ -1597,7 +1600,7 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
15971600
}
15981601

15991602
VPVectorPointerRecipe *clone() override {
1600-
return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1603+
return new VPVectorPointerRecipe(getOperand(0), IndexedTy, Strided,
16011604
getGEPNoWrapFlags(), getDebugLoc());
16021605
}
16031606

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

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

2128-
Value *Increment = createStepForVF(Builder, IndexTy, State.VF, CurrentPart);
2128+
// TODO: Support non-unit-reverse strided accesses.
2129+
int64_t Step = Strided ? -1 * CurrentPart : CurrentPart;
2130+
Value *Increment = createStepForVF(Builder, IndexTy, State.VF, Step);
21292131
Value *ResultPtr =
21302132
Builder.CreateGEP(IndexedTy, Ptr, Increment, "", getGEPNoWrapFlags());
21312133

0 commit comments

Comments
 (0)