Skip to content

perf(sir-opt): share one state SSA analysis among sink recipe stability checks - #2003

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/perf/1998-shared-load-versions
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/perf/1998-shared-load-versions

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Effect-case dispatch planning checks each sink recipe's frontier loads with loads_are_stable_at. That function ran StateSsa::analyze_selected_loads_two_state over just those loads, which scans every instruction of the execution unit. It ran for each case context of each sink recipe, at two call sites, so the cost was O(recipes × unit size) per selector group.

Change

State SSA versions an exact location from that location's own definitions, kills and phis. So one analysis selecting every load of a region versions each location as an analysis of fewer loads does. plan_best_effect_case_dispatch now keeps a LoadVersions per unit: one shared analysis per region, built on first use. Each recipe reads its verdict from it.

The parts of the per-recipe analysis that depend on the selection are handled explicitly:

  • Slot types. Under the two-state contract a location's type is valid only if every selected load at it, and every exact store to it, has its width. The shared analysis leaves out loads that would make their location invalid in every selection containing them: loads without a valid type, and loads at locations whose exact stores lack one. Such a load then has no version in the shared analysis, as in its recipe's own analysis, so the recipe is not stable.
  • Slots for packed loads. Only static loads create a slot. A packed load of the same bits reads that slot, so the recipe must itself contain such a static load.
  • Failures. If the shared analysis fails, the recipe is analyzed on its own, as before.

Every verdict is the same as before. The cost is one scan per region plus the size of each recipe.

Tests

  • New control_region_feasibility::tests::shared_load_versions_match_per_recipe_analysis (equivalence against the current per-recipe analysis). It builds random units with a branch, a join and a loop, containing overlapping static loads and stores, packed and dynamic loads, wrong-width, four-state and untyped registers, and zero-width accesses. For random load selections at every target block (over 10,000 checks, more than 100 of them stable), the shared verdict equals loads_are_stable_at_by_analysis. The test fails if the per-recipe packed-load location check is removed, or if the shared selection keeps the invalidating loads.
  • Affected tests with CI features (celox/systemverilog,celox-test-suite/{verilator,icarus,xezim,runtime-cases}) over celox, celox-frontend-sv, celox-test-suite and celox-sir-opt: 15199 passed, 331 skipped.
  • cargo clippy -p celox-sir-opt --all-targets -D warnings and cargo fmt --check are clean.

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

Closes #1998

…ty checks

Effect-case dispatch planning checked each sink recipe's loads with a
StateSsa analysis of just those loads, which scans the whole execution
unit: O(recipes x unit size) per selector group.

State SSA versions an exact location from that location's own
definitions and kills, so one analysis selecting every load of a region
versions each location as an analysis of fewer loads does. The unit now
builds that analysis once per region, on first use, and each recipe reads
its verdict from it:
- The shared analysis leaves out the loads that make their location
  invalid in every selection containing them, so they have no version
  there, as in their recipe's own analysis.
- A packed load is versioned only when its recipe also has a static load
  of the same bits, as a slot exists only for those.
If the shared analysis fails, the recipe is analyzed on its own as before.
Every verdict is the same.

Closes #1998

Change-Id: Ief18a8459b6318c3dc619453041e66c9fc9aa13d
@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:42:24.913042Z 6bf6291 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 30 minutes 58 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 e498a11 into master Oct 25, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/perf/1998-shared-load-versions branch October 25, 2026 12:37
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 2026
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(sir-opt): control-region feasibility analyzes the whole unit's state SSA for every sink recipe

1 participant