[llvm] [LoopCacheAnalysis] Replace delinearization for fixed size array (PR #164798)
Ryotaro Kasuga via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 04:37:58 PST 2025
================
@@ -355,22 +355,18 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
}
bool IndexedReference::tryDelinearizeFixedSize(
- const SCEV *AccessFn, SmallVectorImpl<const SCEV *> &Subscripts) {
- SmallVector<int, 4> ArraySizes;
- if (!tryDelinearizeFixedSizeImpl(&SE, &StoreOrLoadInst, AccessFn, Subscripts,
- ArraySizes))
+ const SCEV *AccessFn, SmallVectorImpl<const SCEV *> &Subscripts,
+ const SCEV *ElementSize) {
+ const SCEV *Offset = SE.removePointerBase(AccessFn);
+ if (!delinearizeFixedSizeArray(SE, Offset, Subscripts, Sizes, ElementSize)) {
+ Sizes.clear();
return false;
+ }
- // Populate Sizes with scev expressions to be used in calculations later.
- for (auto Idx : seq<unsigned>(1, Subscripts.size()))
- Sizes.push_back(
- SE.getConstant(Subscripts[Idx]->getType(), ArraySizes[Idx - 1]));
-
- LLVM_DEBUG({
- dbgs() << "Delinearized subscripts of fixed-size array\n"
- << "GEP:" << *getLoadStorePointerOperand(&StoreOrLoadInst)
- << "\n";
- });
+ // Drop the last element of Sizes which is the same as ElementSize.
+ assert(!Sizes.empty() && Sizes.back() == ElementSize &&
+ "Expecting the last one to be the element size");
----------------
kasuga-fj wrote:
If we have the following LLVM,
```llvm
...
%gep = getelementptr i8, ptr %p, i64 %offset
store i32 0, %gep
```
to delinearize `%gep` as an i32 array, `%offset` must be a multiple of 4. We need to tell this information to delinearization function, and it's now passed as `ElementSize`. For historical reasons, delinearizer appends it to the end of `Sizes`.
https://github.com/llvm/llvm-project/pull/164798
More information about the llvm-commits
mailing list