Skip to content

perf(sv): skip the always_comb alternative nothing can watch - #1859

Merged
mergify[bot] merged 5 commits into
masterfrom
perf/sv-skip-unwatched-comb-lowering
Oct 24, 2026
Merged

mergify[bot] merged 5 commits into
masterfrom
perf/sv-skip-unwatched-comb-lowering

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1754.

In a design with at least one wait site, every always_comb that may store a variable twice was lowered twice: symbolically, and as an imperative gated unit (lower_comb_alternative). Assembly keeps the unit only if a wait or a flip-flop domain counts one of its candidates (choose_comb_alternatives). Otherwise the second lowering was wasted.

Change

Before comb lowering, attach_instance_glue collects the variables of the module that a counted signal can be:

  • wait terms;
  • flip-flop triggers (clocks and resets of every FF block map);
  • event copies;
  • package variables;
  • identifiers of instance connection actuals, and port-assignment targets;
  • every port, if another module instantiates this one.

watchable_variables closes this set over the comb processes and port assignments, in both directions. When a process writes or reads a watchable variable, every variable it writes or reads becomes watchable. This holds at any width and through any expression: part-selects, concatenations, arithmetic. It is wider than what assembly can count: clock-domain unification aliases only whole-variable copies, and wait terms aren't aliased at all. lower_comb_alternative now runs only for a process whose symbolic targets or syntactic writes (ProcModule::written_variables, including callee bodies) meet that set.

Two cases still lower every alternative as before:

  • A design with a nonblocking switch. Every declared counter slot keeps NBA targets queued (the observed set of staged NBAs), so dropping a slot could change the SIR.
  • The mixed Veryl/SV path (foreign), where the module doesn't see its foreign parents or children.

Perf

SIR: base is eb30f0e. A dump of the post-optimized SIR of all 669 SV suite designs (after the closure was widened), timed ones included, is byte-identical between base and branch. No suite design takes the skip. Every one of the 12 alternatives the suite lowers has a target that a wait or trigger names directly (the #1726 watched-comb cases), so the suite covers the keep path. The unit test comb_alternatives_only_for_watchable_targets covers the skip and these keep cases:

  • a waited target;
  • a waited source;
  • waits through a part-select, a concatenation and an arithmetic expression;
  • a clock aliased through assign c = y[0];
  • a design with a nonblocking switch;
  • a child output port waited on in the parent.

It also checks that a hierarchical reference (@(child.y)) is rejected ("structure member"), so only ports reach another module's variables.

The new timing case intermediate_combinational_writes_reach_part_select_waiters_settled waits on assign w = y[3:0] while an always_comb rewrites y through 0. It passes against Icarus and Verilator: all three print y=26 w=6 n=2, one event per settled change. Its Icarus and Verilator results are not added to the retained reports: CONTRIBUTING.md takes new passing cases without a baseline refresh.

Compile time, callgrind Ir of building the scheduler gate (64 always_ff lanes, an XOR-reduction always_comb sum loop over 64 lanes, initial forever @(posedge clk) stim = stim + 3), median of 5:

design base branch Δ
b1: gate, sum unwatched 1,048,559,506 914,588,153 -12.8%
c: b1 + a watched always_comb w (@(w)) 985,468,743 852,105,389 -13.5%
b1 with sum unrolled (64 statements), before the closure was widened 482,763,232 479,285,267 -0.7%

In c, w is still lowered twice and keeps its unit; only sum is skipped.

SV suite build (the digest test binary, building all 668 designs; perf stat instructions:u, 3 runs each): base 261,190,795,729 / 261,194,965,554 / 261,198,491,989, branch 261,194,940,307 / 261,196,035,760 / 261,199,459,779. Equal (+0.0004% median). The watch set costs nothing measurable.

Validation

All runs use the systemverilog feature:

  • celox --test systemverilog: 4356 passed.
  • celox-sv-analyzer, celox-frontend-sv and celox-test-suite tests: 0 failed.
  • retained_reports: passed.
  • celox --lib traces: 4 passed.
  • clippy -D warnings: clean.
  • sv-tests conformance: identical to expected.tsv.

In a design with a wait, every always_comb that may store a variable
twice was also lowered as an imperative unit, which assembly drops
unless a wait or flip-flop domain counts one of its targets. A module
now collects what may name its variables: wait terms, triggers, event
copies, package variables, instance connections, ports of an
instantiated module, and whatever a same-width write and read of a
combinational process connects to them. The second lowering runs only
for a process whose targets meet that set. Designs with a nonblocking
switch or with foreign modules lower every alternative as before.

Closes #1754

Change-Id: I6ca8cdf3e1561a784cd9ac5536b8d42b3618b9a3
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T16:19:25.925523Z 050ece5 New commits
ℹ️ 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 merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

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

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 20 minutes 48 seconds in the queue, with no time running CI.

Reason

The pull request #1859 has been manually updated

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

Requeued — the merge queue status continues in this comment ↓.

A process that writes a watchable variable or reads one makes all the
variables it writes and reads watchable, at any width and through any
expression, not only same-width pairs. Unit tests keep the alternative
for waits through a part-select, a concatenation and an arithmetic
expression, and check that a hierarchical reference is rejected.

Change-Id: Ib61347656ea07409622b103f02eeb213d3405364
Change-Id: I9f2a272e29a62dcb551993e8ca60979cb137fb92

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e76981dd4b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
written_variables now maps every output and inout formal of a user
call, and every argument a system function writes, to the names of its
actual argument, for calls in statements and expressions and through
the bodies of callees. A process that writes only through such an
argument, like `always @* if ($random(w) && y[0]) ...` or a function
that writes its output only through a nested system call, keeps its
group, so a wait on the argument keeps the alternative of what it reads.

Change-Id: I6bd823800910fabb75486fb969f84cbe6647f941

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dbeeb17fde

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Change-Id: Ibfaeb92d38d799b99267b34c2bb5e72e9f55565b
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-24 17:30 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1859 on master (d34520d) #1919
  • ✅ Merged — 2026-10-24 18:01 UTC · at c43006140783f921a0811ec094ff948af2078a8f · merge

This pull request spent 31 minutes 10 seconds in the queue, including 28 minutes 52 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 mentioned this pull request Oct 24, 2026
40 of 71 tasks
@mergify
mergify Bot merged commit c430061 into master Oct 24, 2026
31 checks passed
@mergify
mergify Bot deleted the perf/sv-skip-unwatched-comb-lowering branch October 24, 2026 18:01
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 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(sv): skip the second always_comb lowering when nothing can watch its targets

1 participant