Skip to content

perf(native): reuse clobber walks across reload queries of one byte range - #1997

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

mergify[bot] merged 1 commit into
masterfrom
feature/perf/1994-clobber-memo

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Every reload query ran a fresh clobber walk from its start:

  • ReloadMemorySsa::snapshot_at opened a new ClobberWalker session for each snapshot.
  • The walker memoizes only within one session.
  • clobber_cache keeps only the final answer per (load, start).

So walks from different starts re-scanned the same memory definitions and ran the alias oracle over each definition's write effects every time. That is O(queries × definitions × effects). On C906 the oracle (snapshot_at::{closure#3}) took about 35% of the time after the frontend.

Change

celox-analysis gets a ClobberMemo and ClobberWalker::query_memoized, and reload keeps one memo per queried byte range. The memo holds only accesses whose walk met no unresolved cycle, meaning no in-progress access on the walk stack and no reuse of a result that met one.

Why reusing these results is exact:

  • Such a walk covers an acyclic part of the graph. That part is fixed by the query: an aliasing definition stops the walk, a disjoint one continues to its predecessor, and a MemoryPhi continues to its inputs.
  • On that part, the walker computes the same result whatever the session's start points or stack.
  • Accesses whose walk met a cycle depend on the MemoryPhi being resolved. They are not memoized and are walked in each session exactly as before.

Every query therefore resolves as it did, the reload recipes do not change, and each definition is checked against the oracle once per byte range instead of once per walk.

Tests

  • New memory_ssa::tests::memoized_sessions_match_fresh_sessions (equivalence against the current walker). Over random CFGs with loops, joins and disjoint, overlapping and repeated stores, sequences of multi-start sessions sharing a memo give exactly the results of fresh sessions, with fewer oracle calls. The test fails if cyclic results are also memoized.
  • Affected tests with CI features (celox/systemverilog,celox-test-suite/{verilator,icarus,xezim,runtime-cases}) over celox, celox-frontend-sv, celox-test-suite, celox-analysis and celox-backend-x86: 15383 passed, 330 skipped.
  • cargo clippy -p celox-analysis -p celox-backend-x86 --all-targets -D warnings and cargo fmt --check are clean.

Like the other complexity-order fixes, this PR has no before/after benchmark.

Closes #1994

…ange

Each reload snapshot ran a fresh clobber walk from its start: the walker
memoized results only within one query session, and the reload clobber
cache kept only the final answer per (load, start). Walks from different
starts re-scanned the same memory definitions, running the alias oracle
over each definition's write effects every time. On C906 the oracle took
about 35% of the time after the frontend.

A ClobberMemo now keeps, per queried byte range, the clobbers of accesses
whose walk met no unresolved cycle. Such a walk covers an acyclic part of
the graph, which determines its result whatever the start points, so
later sessions reuse it without walking again. Accesses whose walk met a
cycle depend on the MemoryPhi being resolved and are walked in each
session as before, so every query resolves exactly as it did and the
reload recipes do not change.

Closes #1994

Change-Id: I93e7a99f5d74451307b5249b6e22f1c591f9e047
@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-25T11:29:24.564447Z 2c85a69 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 39 minutes 21 seconds in the queue, including 26 minutes 23 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 f7aac90 into master Oct 25, 2026
24 checks passed
@mergify
mergify Bot deleted the feature/perf/1994-clobber-memo branch October 25, 2026 12:37
@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.

perf(native): reload clobber queries re-walk memory definitions for every start

1 participant