Repository navigation
perf(native): reuse clobber walks across reload queries of one byte range - #1997
Merged
Merged
Conversation
…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
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 39 minutes 21 seconds in the queue, including 26 minutes 23 seconds running CI. Required conditions to merge
|
This was referenced Oct 25, 2026
This was referenced 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
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.
Every reload query ran a fresh clobber walk from its start:
ReloadMemorySsa::snapshot_atopened a newClobberWalkersession for each snapshot.clobber_cachekeeps 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-analysisgets aClobberMemoandClobberWalker::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:
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
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.celox/systemverilog,celox-test-suite/{verilator,icarus,xezim,runtime-cases}) overcelox,celox-frontend-sv,celox-test-suite,celox-analysisandcelox-backend-x86: 15383 passed, 330 skipped.cargo clippy -p celox-analysis -p celox-backend-x86 --all-targets -D warningsandcargo fmt --checkare clean.Like the other complexity-order fixes, this PR has no before/after benchmark.
Closes #1994