Skip to content

fix(native): bound the memory of memoized reload clobber walks - #2037

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/fix/clobber-memo-bound
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/fix/clobber-memo-bound

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

#1997 added, for each queried byte range, a ClobberMemo that 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

ReloadMemorySsa counts 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. ClobberMemo gets len/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_sessions now also drops the memo at random points between sessions, and still matches fresh sessions.
  • Affected tests with CI features (celox/{systemverilog,cranelift,wasm-runtime,wasm-component,veryl-reference}, celox-test-suite/{verilator,icarus,xezim,runtime-cases}) over celox, celox-frontend-sv, celox-test-suite, celox-analysis and celox-backend-x86: 15496 passed, 330 skipped.
  • rtlmeter C906, native --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.
  • b2_vm_dispatch_bit callgrind (release, native, --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

#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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T14:47:08.438008Z a0fa235 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
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
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify
mergify Bot merged commit a64224f into master Oct 25, 2026
24 checks passed
@mergify
mergify Bot deleted the feature/fix/clobber-memo-bound branch October 25, 2026 15:49
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(native): reload clobber memos grow without bound on large four-state functions

1 participant