Skip to content

Commit 2ad2cdc

Browse files
committed
Find base pointer and stride after profitable check
1 parent a3f18ae commit 2ad2cdc

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4581,8 +4581,7 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan, VPCostContext &Ctx,
45814581
VPTypeAnalysis TypeInfo(Plan);
45824582
DenseMap<VPWidenGEPRecipe *, std::tuple<VPValue *, VPValue *, Type *>>
45834583
StrideCache;
4584-
SmallVector<VPRecipeBase *> ToErase;
4585-
SmallPtrSet<VPValue *, 4> PossiblyDead;
4584+
SmallVector<VPWidenMemoryRecipe *> ToErase;
45864585
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
45874586
vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) {
45884587
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
@@ -4605,23 +4604,6 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan, VPCostContext &Ctx,
46054604
if (!PtrUV)
46064605
continue;
46074606

4608-
// Try to get base and stride here.
4609-
VPValue *BasePtr, *StrideInElement;
4610-
Type *ElementTy;
4611-
auto It = StrideCache.find(Ptr);
4612-
if (It != StrideCache.end())
4613-
std::tie(BasePtr, StrideInElement, ElementTy) = It->second;
4614-
else
4615-
std::tie(BasePtr, StrideInElement, ElementTy) = StrideCache[Ptr] =
4616-
determineBaseAndStride(Ptr);
4617-
4618-
// Skip if the memory access is not a strided access.
4619-
if (!BasePtr) {
4620-
assert(!StrideInElement && !ElementTy);
4621-
continue;
4622-
}
4623-
assert(StrideInElement && ElementTy);
4624-
46254607
Instruction &Ingredient = MemR->getIngredient();
46264608
auto IsProfitable = [&](ElementCount VF) -> bool {
46274609
Type *DataTy = toVectorTy(getLoadStoreType(&Ingredient), VF);
@@ -4637,12 +4619,25 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan, VPCostContext &Ctx,
46374619
};
46384620

46394621
if (!LoopVectorizationPlanner::getDecisionAndClampRange(IsProfitable,
4640-
Range)) {
4641-
PossiblyDead.insert(BasePtr);
4642-
PossiblyDead.insert(StrideInElement);
4622+
Range))
4623+
continue;
4624+
4625+
// Try to get base and stride here.
4626+
VPValue *BasePtr, *StrideInElement;
4627+
Type *ElementTy;
4628+
auto It = StrideCache.find(Ptr);
4629+
if (It != StrideCache.end())
4630+
std::tie(BasePtr, StrideInElement, ElementTy) = It->second;
4631+
else
4632+
std::tie(BasePtr, StrideInElement, ElementTy) = StrideCache[Ptr] =
4633+
determineBaseAndStride(Ptr);
4634+
4635+
// Skip if the memory access is not a strided access.
4636+
if (!BasePtr) {
4637+
assert(!StrideInElement && !ElementTy);
46434638
continue;
46444639
}
4645-
PossiblyDead.insert(Ptr);
4640+
assert(StrideInElement && ElementTy);
46464641

46474642
// Create a new vector pointer for strided access.
46484643
auto *GEP = dyn_cast<GetElementPtrInst>(PtrUV->stripPointerCasts());
@@ -4677,9 +4672,10 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan, VPCostContext &Ctx,
46774672
}
46784673
}
46794674

4680-
// Clean up dead memory access recipes, and unused base address and stride.
4681-
for (auto *R : ToErase)
4675+
// Clean up dead recipes.
4676+
for (auto *R : ToErase) {
4677+
VPValue *Addr = R->getAddr();
46824678
R->eraseFromParent();
4683-
for (auto *V : PossiblyDead)
4684-
recursivelyDeleteDeadRecipes(V);
4679+
recursivelyDeleteDeadRecipes(Addr);
4680+
}
46854681
}

0 commit comments

Comments
 (0)