Repository navigation
[Codegen] Don't hoist statically-bound allocations with bogus huge bounds - #24627
Open
Alex-Wengg wants to merge 1 commit into
Open
Alex-Wengg wants to merge 1 commit into
Alex-Wengg wants to merge 1 commit into
Conversation
Contributor
|
Hey, I also ran into the same problem as #24483 for the VMVX backend and the changes in this PR would fix this for me, so I wanted to ask if you still intend to merge these changes or not? |
…unds hoistOneStaticallyBoundAllocation used the result of computeConstantBound verbatim as the static dimension of a hoisted alloca. An unconstrained `index` operand carries the trivial type-level upper bound (2^53 - 1), so a single `affine.apply` (e.g. `ceildiv 2`) turns it into a ~2^52-element static `memref.alloca` (~16 PiB), emitted silently. Downstream stride/size math then overflows i64 and the dispatch reads/writes undefined memory. Refuse to hoist when the product of the constant bounds exceeds a generous element-count cap (2^32), leaving the allocation dynamic, which is always valid. Scalable bounds are skipped in the product (vscale >= 1, so it is still a lower bound). The cap is intentionally backend-agnostic rather than the target's max_stack_allocation_size: the stack check still enforces the real limit downstream on LLVMCPU, and a budget-based cap would stop hoisting legitimately large tiles when that check is disabled. Fixes iree-org#24483. Signed-off-by: Alex-Wengg <[email protected]>
Alex-Wengg
force-pushed
the
fix-24483-hoist-umax-alloca
branch
from
November 16, 2026 16:09
950920c to
bb85bb4
Compare
Alex-Wengg
marked this pull request as ready for review
November 16, 2026 16:35
Alex-Wengg
requested review from
AGindinson,
egebeysel and
phemashekar
as code owners
November 16, 2026 16:35
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
hoistOneStaticallyBoundAllocationuses the result ofcomputeConstantBoundas the static shape of the hoisted alloca. For a dim derived from an
unconstrained
indexvalue that bound is the type-level2^53 - 1, so the#24483 reproducer hoists to
memref.alloca() : memref<4503599627370496xi32>(~16 PiB) with no diagnostic.
Since #24745 the LLVMCPU stack check is overflow-safe, so there this now fails
to compile instead of miscompiling. VMVX bufferizes through the same
cpuAllocationFnbut has no such check, so it still gets the bogus staticalloca silently.
Fix
Don't hoist when the product of the constant bounds exceeds 2^32 elements; the
alloca stays dynamic, which is always valid. Scalable bounds are skipped in the
product (vscale >= 1, so it is still a lower bound).
The cap is a fixed, backend-agnostic sanity limit rather than the target's
max_stack_allocation_size(as in #24527): with--iree-llvmcpu-fail-on-out-of-bounds-stack-allocation=falsethe stack checkis off, and a budget-based cap would stop hoisting legitimately large tiles.
Real tiles are KB to MB, far below 2^32 elements.
Testing
@no_hoist_umax_bounded_allocaand@no_hoist_umax_bounded_scalable_allocaunder both RUN configs; existingcases unchanged. The scalable one fails if the loop stops at the first
scalable bound.
hoistOneStaticallyBoundAllocationproduces bogus 2^52-element staticallocas when dynamic dim bounds default to theindexumax #24483 reproducer:memref<4503599627370496xi32>before,memref.alloca(%dim) : memref<?xi32>after.Fixes #24483.
Assisted-by: Claude Code