[llvm] [LV] Convert gather loads with constant stride into strided loads (PR #147297)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 12 03:24:55 PDT 2026
================
@@ -5958,3 +5983,107 @@ void VPlanTransforms::createPartialReductions(VPlan &Plan,
transformToPartialReduction(Chain, CostCtx.Types, Plan, Phi, RK);
}
}
+
+void VPlanTransforms::convertToStridedAccesses(VPlan &Plan,
+ PredicatedScalarEvolution &PSE,
+ Loop &L, VPCostContext &Ctx,
+ VFRange &Range) {
+ if (Plan.hasScalarVFOnly())
+ return;
+
+ VPTypeAnalysis TypeInfo(Plan);
+ VPRegionBlock *VectorLoop = Plan.getVectorLoopRegion();
+ SmallVector<VPWidenMemoryRecipe *> ToErase;
+ VPValue *I32VF = nullptr;
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_shallow(VectorLoop->getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+ auto *LoadR = dyn_cast<VPWidenLoadRecipe>(&R);
+ // TODO: Support strided store.
+ // TODO: Transform reverse access into strided access with -1 stride.
+ // TODO: Transform gather/scatter with uniform address into strided access
+ // with 0 stride.
+ // TODO: Transform interleave access into multiple strided accesses.
+ if (!LoadR || LoadR->isConsecutive())
+ continue;
+
+ auto *Ptr = dyn_cast<VPWidenGEPRecipe>(LoadR->getAddr());
+ if (!Ptr)
+ continue;
+
+ Instruction &Ingredient = LoadR->getIngredient();
+ auto IsProfitable = [&](ElementCount VF) -> bool {
+ Type *DataTy = toVectorTy(getLoadStoreType(&Ingredient), VF);
+ const Align Alignment = getLoadStoreAlignment(&Ingredient);
+ if (!Ctx.TTI.isLegalStridedLoadStore(DataTy, Alignment))
+ return false;
+ const InstructionCost CurrentCost = LoadR->computeCost(VF, Ctx);
+ const InstructionCost StridedLoadStoreCost =
+ Ctx.TTI.getMemIntrinsicInstrCost(
+ MemIntrinsicCostAttributes(
+ Intrinsic::experimental_vp_strided_load, DataTy,
+ Ptr->getUnderlyingValue(), LoadR->isMasked(), Alignment,
+ &Ingredient),
+ Ctx.CostKind);
+ return StridedLoadStoreCost < CurrentCost;
+ };
+
+ if (!LoopVectorizationPlanner::getDecisionAndClampRange(IsProfitable,
+ Range))
+ continue;
+
+ const SCEV *PtrSCEV = vputils::getSCEVExprForVPValue(Ptr, PSE, &L);
+ const SCEV *Start;
+ const APInt *Step;
+ // TODO: Support loop invariant stride.
----------------
Mel-Chen wrote:
Yes, updated.
57207ee40c85149fe43b9b99361d9b335d12815f
https://github.com/llvm/llvm-project/pull/147297
More information about the llvm-commits
mailing list