[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:42 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);
----------------
david-arm wrote:

It's not necessary to write the code like this. The `; Bound` bit is redundant. You can just do:

```
  if (std::optional<uint64_t> Bound = Legal->getBoundedLoadBound(I))
    if (VF.isFixed() && VF.getFixedValue() ...)
```

https://github.com/llvm/llvm-project/pull/207279


More information about the llvm-commits mailing list