[llvm] [LV] Support strided load with a stride of -1 (PR #128718)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 01:45:13 PDT 2025
================
@@ -2519,6 +2530,75 @@ void VPlanTransforms::dissolveLoopRegions(VPlan &Plan) {
R->dissolveToCFGLoop();
}
+void VPlanTransforms::convertToStridedAccesses(VPlan &Plan, VPCostContext &Ctx,
+ VFRange &Range) {
+ if (Plan.hasScalarVFOnly())
+ return;
+
+ SmallVector<VPRecipeBase *> ToErase;
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+ auto *MemR = dyn_cast<VPWidenMemoryRecipe>(&R);
+ // TODO: support strided store
+ // TODO: support strided accesses with stride not equal to -1
+ if (!MemR || !isa<VPWidenLoadRecipe>(MemR) || !MemR->isReverse())
+ continue;
+
+ Instruction &Ingredient = MemR->getIngredient();
+ Type *ElementTy = getLoadStoreType(&Ingredient);
+
+ auto IsProfitable = [&](ElementCount VF) -> bool {
+ Type *DataTy = toVectorTy(ElementTy, VF);
+ const Align Alignment = getLoadStoreAlignment(&Ingredient);
+ if (!Ctx.TTI.isLegalStridedLoadStore(DataTy, Alignment))
+ return false;
+ const InstructionCost CurrentCost = MemR->computeCost(VF, Ctx);
+ const InstructionCost StridedLoadStoreCost =
+ Ctx.TTI.getStridedMemoryOpCost(
+ Ingredient.getOpcode(), DataTy,
+ getLoadStorePointerOperand(&Ingredient), MemR->isMasked(),
----------------
fhahn wrote:
Would be good to avoid passing the pointer operand from the ingredient here, as it may not be accurate any longer. What does the interface use the pointer operand for? Ideally we would pass the required info directly w/o having to pass an IR value. Do you think that would be feasible?
Otherwise, can we pass the underlying value from the pointer operand, if it exists?
https://github.com/llvm/llvm-project/pull/128718
More information about the llvm-commits
mailing list