Skip to content

perf(sv): fold zero-argument functions whose kept result is never read - #2704

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/taxi-compilation-perf
Oct 31, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/taxi-compilation-perf

Conversation

@tignear

@tignear tignear commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Taxi's LFSR builds its 122x122-bit mask in wire mask = lfsr_mask();, a static zero-argument function that assigns its result bit by bit (lfsr_mask[i][j] = ... with REVERSE=1). The analyzer cannot prove that every call assigns all of the result, so it stays static storage kept between calls (IEEE 1800-2023 13.4.2). Two things followed:

  • RuntimeConstantFunctions rejected the function because it has persistent storage, so the call was not evaluated once as a constant.
  • ProcModule::reads_simulation_state counted the call as reading state, so the continuous assignment went through the FF lowering path and the function body became runtime logic: 11k comb blocks and 1.8M MIR instructions, with most of the compile spent in register allocation and spill planning.

Without arguments, and without any read of that result, every call performs the same assignments. The bits no call assigns keep their initial value (0 in two-state, X in four-state), so each call returns what the first does. This PR accepts such functions for constant evaluation and stops treating a call that lowers to its constant as reading state. A read of the result, including through the index of an assignment target, keeps the call.

Effect (celox vpi build, one pinned CPU, heliodor-dev build)

Taxi case before after
lfsr64 125 s CPU, peak RSS 1.7 GiB 18 s, 243 MiB
phy64 281 s CPU, peak RSS 2.1 GiB 50 s, 288 MiB

The latest published CI values are 171 s (lfsr64) and 342 s (phy64) for Celox, against 24 s and 42 s for Verilator. The companion PR that parses wide literals in linear time brings these further down to 10 s and 24 s.

Validation

  • celox-sv-analyzer lib tests (933) and celox-frontend-sv lib tests (11) pass. New tests: a partially assigned static result folds to its initial-value bits in both state modes, and results read directly or through an assignment-target index stay calls. The frontend runtime-loop test gains a variant whose result keeps bits between calls.
  • New shared cases procedural::static_function_unread_partial_result_{is_constant,keeps_unknown_bits}: pass on every Celox backend. Verilator passes the two-state case and reports the four-state case as unsupported (expected). Icarus passes both.
  • systemverilog vtest filter procedural:: | operators:: | constant_function | static_function: 688 passed.
  • Taxi run-taxi-bench.py run {lfsr64,phy64} --samples 1: all tests pass, with simulated durations equal to Verilator's and no change in test-body time.

Taxi's LFSR builds its 122x122-bit mask in `wire mask = lfsr_mask();`, a static
zero-argument function that assigns its result bit by bit. The analyzer cannot
prove that every call assigns all of it, so the result stays static storage
kept between calls (IEEE 1800-2023 13.4.2). That excluded the function from the
evaluate-once constant path, and the call made its process count as reading
simulation state. The function body was then generated as runtime logic of
1.8M machine instructions, which spent most of the compile in register
allocation.

Without arguments and without any read of that result, every call performs the
same assignments, so the bits no call assigns keep their initial value and each
call returns what the first does. Accept such functions for constant evaluation,
and do not treat a call that lowers to its constant as reading state. A read of
the result, including through an assignment target index, keeps the call.

Single-CPU `celox vpi build`: lfsr64 125 s -> 18 s with a peak RSS of 1.7 GiB ->
243 MiB, and phy64 281 s -> 50 s with 2.1 GiB -> 288 MiB. The Taxi cocotb tests
of both configurations pass with the same simulated durations as Verilator.

Change-Id: I740502a83e35de07efdaf2e88e8dcd12ccee6cd4
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-31T08:52:41.268908Z d5e939b 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 31, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 31, 2026
@mergify

mergify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into master as f33cfb9 at 09:59 UTC

Merged together with #2695, #2703. 19 min in the queue, 17 min of it CI.

So far

9 merge conditions met
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • check-success = Verify workflow lockfile
  • any of · required by 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 · required by 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 · required by 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 · required by 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
  • any of · required by GitHub repository ruleset rule master:
    • check-success = @github-actions/Queue validation
    • check-neutral = @github-actions/Queue validation
    • check-skipped = @github-actions/Queue validation
  • any of · required by GitHub repository ruleset rule master:
    • check-success = @github-actions/Verify workflow lockfile
    • check-neutral = @github-actions/Verify workflow lockfile
    • check-skipped = @github-actions/Verify workflow lockfile

Times in UTC · dashboard · how the merge queue works

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.

1 participant