Repository navigation
Fix prefetches of struct-typed buffers and under loop-dependent lets - #9612
Merged
Merged
Conversation
alexreinking
force-pushed
the
alexreinking/prefetch-fixes
branch
from
October 26, 2026 19:58
95ddbd5 to
82a5fe1
Compare
alexreinking
force-pushed
the
alexreinking/prefetch-fixes
branch
from
October 26, 2026 23:05
82a5fe1 to
d645519
Compare
slomp
approved these changes
Oct 27, 2026
Two bugs in prefetch lowering: - StorageFlattening emitted a struct-typed prefetch call, which is rejected, since struct-typed Exprs may only appear as field()'s argument or a Store's value. Prefetch the buffer's bytes instead: the offset and strides in bytes, with the record's bytes as the innermost dimension. - InjectPrefetch computed the prefetched box from the body under the prefetch with the loop variable advanced by the offset, but the lets between the loop and the prefetch (e.g. bounds inference's, of a realization within a GuardWithIf tile) still held their values at the current iteration. Re-wrap those lets so they're evaluated at the prefetched iteration too. Before, the test's 6-row prefetch was 2 rows. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
alexreinking
force-pushed
the
alexreinking/prefetch-fixes
branch
from
November 2, 2026 23:50
d645519 to
95988cd
Compare
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.
This PR fixes two bugs in prefetch lowering. Both showed up when prefetching the weights in the GGML app (#9511).
Struct-typed buffers.
StorageFlatteningemitted a struct-typedprefetchcall. Struct-typed Exprs may only appear asfield()'s argument or as a Store's value, so compilation failed. The prefetch is now of the buffer's bytes: the offset and strides are in bytes, and the record's bytes are added as the innermost dimension.Lets that depend on the loop.
InjectPrefetchcomputes the prefetched box by advancing the loop variable by the offset in the body under the prefetch. Lets between the loop and the prefetch kept their values from the current iteration. Bounds inference creates such lets, for example for a realization computed inside aGuardWithIftile. In the test, a tile of 4 rows reads 6 rows of the input, but the prefetch covered only 2 rows (and none in the tail). Those lets are now re-wrapped around the body, so they are evaluated at the prefetched iteration too.correctness_prefetchgains two tests, run on all of its targets:test13prefetches a struct-typed buffer. Without this PR it fails to compile.test14checks the GuardWithIf case above. Without this PR it finds 2 prefetched rows instead of 6.Validation:
ctest -R 'correctness_(prefetch|struct_type)$'on this branch: passed.ctest -L correctnessat the top of the stack (apps/ggml: GGML quantized kernels on Approximations #9511): 704/705 passed. The failure iscorrectness_cross_compilation, which fails because my LLVM build has no Hexagon target.Stacked on #9599.
Checklist