[llvm] [LV] Vectorize bounded (i % 2^N) loads in read only loops w/o RT checks. (PR #207279)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 08:00:41 PDT 2026
================
@@ -2662,20 +2665,27 @@ LoopVectorizationCostModel::memoryInstructionCanBeWidened(Instruction *I,
auto *Ptr = getLoadStorePointerOperand(I);
auto *ScalarTy = getLoadStoreType(I);
- // In order to be widened, the pointer should be consecutive, first of all.
- int Stride = Legal->isConsecutivePtr(ScalarTy, Ptr);
- if (!Stride)
+ // If the instruction's allocated size doesn't equal it's type size, it
+ // requires padding and will be scalarized.
+ auto &DL = I->getDataLayout();
+ if (hasIrregularType(ScalarTy, DL))
return std::nullopt;
- // If the instruction is a store located in a predicated block, it will be
- // scalarized.
+ // If the instruction is located in a predicated block, it will be scalarized.
if (isScalarWithPredication(I, VF))
return std::nullopt;
- // If the instruction's allocated size doesn't equal it's type size, it
- // requires padding and will be scalarized.
- auto &DL = I->getDataLayout();
- if (hasIrregularType(ScalarTy, DL))
+ // Widen a bounded (i % 2^N) load in a read-only loop as a consecutive
+ // vector load when VF divides the bound.
+ if (std::optional<uint64_t> Bound = Legal->getBoundedLoadBound(I);
+ Bound && VF.isFixed()) {
+ if (VF.getFixedValue() <= *Bound && *Bound % VF.getFixedValue() == 0)
----------------
david-arm wrote:
Can't use `ElementCount::getFixed(*Bound).isKnownMultipleOf(VF)` here?
https://github.com/llvm/llvm-project/pull/207279
More information about the llvm-commits
mailing list