Repository navigation
fix(native): bound the memory of memoized reload clobber walks - #2037
Merged
Merged
Conversation
#1997 kept, for each queried byte range, the clobber of every access a walk resolved without meeting a cycle. Those memos grow with the number of byte ranges times the accesses walked and are never dropped: the native four-state compile of rtlmeter C906 climbs about 600 MB/s in reload analysis and is killed at a 16 GiB cap. The memos now hold at most four entries per access of the graph (at least 65536) in all; past that they are dropped, and later queries walk again. A memo is only a cache of results the walk recomputes exactly, so every query resolves as before. Closes #2036 Change-Id: I8e735dc87d556efa18ceae6b011ef4551116ab36
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
Merge Queue Status
This pull request spent 43 minutes 17 seconds in the queue, including 33 minutes 12 seconds running CI. Required conditions to merge
|
40 of 71 tasks
tignear
added a commit
that referenced
this pull request
Oct 25, 2026
…ng clobbers The reload-recipe analysis derived a query-specific view of one whole-memory SSA graph by walking it and folding every MemoryPhi whose inputs agreed for the query. Folding is not well defined on cycles: a phi whose inputs were all still on the walk stack was kept as a version of its own, so a join inside a loop became a distinct version although nothing in the loop wrote the queried bytes, and the result depended on where the walk started. The in-session reuse of such results and the per-(load, start) clobber cache then froze whichever answer came first in dominator order. The spill planner's probe function and the final MIR query different points in a different order, so their certificates differed on identical memory states and materialization failed with RELOAD_RECIPE.STATE_SNAPSHOT_CURRENT (#2041, #2044). celox-analysis gains `memory_versions`: the minimal SSA of every elementary byte range, built directly. A phi for a range is placed exactly at the iterated dominance frontier of the range's writes, with live-on-entry as the root definition, so every phi merges two different reaching versions on any CFG, including irreducible ones, and the version of every byte at every point is a canonical function of the program. Renaming runs once over the dominator tree with a persistent range-assign tree: O((W + F) log A) nodes for W write ranges, F phi ranges and A atoms, and a query costs O(k log A) for k result segments, replacing walks that were O(queries x definitions) or, with the clobber memo, Θ(ranges x accesses) memory. Reload snapshots become per-byte segment maps that reference the function's phi equations, interned once per function as pieces with one input tuple each; snapshots with equal roots share one allocation. The final-MIR verifier compares snapshots run by run with the same ordinal shifting and factoring inlining as before. The clobber walker stays in celox-analysis as a published API and test oracle, without the memo of #1997 and its budget of #2037, which no client uses any more; its module docs record the divergence. Tests: random CFGs with loops, nested loops, irreducible cycles, overlapping ranges and unknown writes against one sparse SSA per atom; random acyclic CFGs against the clobber walker's snapshot equality, where it is exact; the #2041 loop shape as a documented divergence; and the #2044 derived-edge repro. Closes #2041, closes #2044. Change-Id: I2badec66e4eea726e39282d6f994151cdd87e4d2
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.
#1997 added, for each queried byte range, a
ClobberMemothat keeps the clobber of every access a walk resolved without meeting an unresolved cycle. The memos are never dropped, so their size grows with the number of byte ranges times the accesses walked. On the native four-state compile of rtlmeter C906, register allocation climbs about 600 MB/s and is killed at a 16 GiB cap; four-state doubles the ranges (value and mask planes).Change
ReloadMemorySsacounts the entries its memos hold. Before a query, if the count exceeds the budget, it drops every memo. The budget is four entries per access of the memory-SSA graph, at least 65536.ClobberMemogetslen/is_empty.A memo only caches results the walk recomputes exactly, so a dropped memo changes nothing but time. Every query resolves as before, the reload recipes are the same, and so is the generated code.
Tests
memory_ssa::tests::memoized_sessions_match_fresh_sessionsnow also drops the memo at random points between sessions, and still matches fresh sessions.celox/{systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference},celox-test-suite/{verilator,icarus,xezim,runtime-cases}) overcelox,celox-frontend-sv,celox-test-suite,celox-analysisandcelox-backend-x86: 15496 passed, 330 skipped.--four-state, under a 16 GiB cap (c906-int 993c6525d9 plus its local changes; heliodor-dev): without this change it is OOM-killed at 16 GiB after about 1:50. With it, RSS peaks at 3.1 GB (sampled every 2 s) and stays flat through compilation. After compilation the run sits in the BigUint signal-plane writes of image loading (biguint_shr2,memmove), which is perf(runtime): handle unpacked arrays per element instead of as one BigUint #2029, so I stopped it there.--toggle-collect='*SimulationState*step_until*'), master 23411b0 against this branch: JIT code 2,761,200,000 Ir and total 4,195,604,063 Ir on both (identical).The structural fix of the reload analysis (per-location memory SSA, which replaces the memo) is tracked in #2032.
Closes #2036