Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/Analysis/LoopCacheAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class IndexedReference {

/// Attempt to delinearize \p AccessFn for fixed-size arrays.
bool tryDelinearizeFixedSize(const SCEV *AccessFn,
SmallVectorImpl<const SCEV *> &Subscripts);
SmallVectorImpl<const SCEV *> &Subscripts,
const SCEV *ElementSize);

/// Return true if the index reference is invariant with respect to loop \p L.
bool isLoopInvariant(const Loop &L) const;
Expand Down
26 changes: 11 additions & 15 deletions llvm/lib/Analysis/LoopCacheAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Sizes.pop_back();
return true;
}

Expand All @@ -397,7 +393,7 @@ bool IndexedReference::delinearize(const LoopInfo &LI) {

bool IsFixedSize = false;
// Try to delinearize fixed-size arrays.
if (tryDelinearizeFixedSize(AccessFn, Subscripts)) {
if (tryDelinearizeFixedSize(AccessFn, Subscripts, ElemSize)) {
IsFixedSize = true;
// The last element of Sizes is the element size.
Sizes.push_back(ElemSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
; A[c][d][d] = 0;
; }

; CHECK: Loop 'outer.loop' has cost = 9223372036854775807
; CHECK: Loop 'inner.loop' has cost = 9223372036854775807
; CHECK: Loop 'outer.loop' has cost = 10000

Comment on lines -12 to 14
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was added in #111807. Based on the description of the PR, the test appears to ensure that no assertion errors are triggered, so I believe this change is not particularly significant.

Copy link
Member

@Meinersbur Meinersbur Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjoerdmeijer Can you confirm? Seems that it is basically ceiling the cost number to UINT64_MAX, so inner.loop is still tresting that.

@A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16

Expand Down