Repository navigation
perf(optimize): strip deopt states, prune dead loop params, inline pure leaves - #327
Merged
Merged
Conversation
…aves The bytecode path never reads a deopt state, but the states kept dead loop temporaries alive, so the emitter carried them through every back edge. The SSA round trip now strips states ahead of its pipeline, and DCE removes block params nothing reads together with the edge arguments feeding them. Entry params are always kept; the JIT tiers keep their states. optimize.O3 also inlines pure scalar leaves ahead of the strip. The bytecode path inlines only a body that cannot trap, since a trap would otherwise be reported in the caller's frame. Threaded O3 vs O0: mandelbrot 0.95 -> 1.15, spectral-norm 0.95 -> 1.13, permutation-flips 0.94 -> 1.00, string-compare 0.88 -> 1.00, fannkuch 0.94 -> 0.97; no kernel regresses beyond noise. JIT ratios are unchanged within noise. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…llees DCE pushed the edge arguments of live non-entry params only, so a back edge into block 0 lost its argument; it now pushes them for entry params too. The bytecode inliner read callee code that an earlier round trip had already rewritten in place, which a later rollback would not undo in the caller. SSAPass now resolves callees through copies taken before any rewrite. Its option layer is a bool, and the inliner flag is renamed trapless so it no longer shares a name with LICM's quiet. Docs and tests state that stripped SSA is outside the ssa.Verify contract, that PromotePass may add a state back, that inlining removes a call's frame and stack use (pinned by a frame-limit test), and that a constant zero divisor keeps its call. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
This was referenced Nov 11, 2026
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.
Summary
The bytecode optimizer (
optimize→transform.SSAPass) now:InlinePasswith atraplessrule, so only pure scalar leaves whose body cannot trap are inlined. A division or remainder by a nonzero constant is allowed. Callees are read from copies taken before any rewrite, so a rewrite that is later rolled back leaves nothing in a caller.StripPass), because emission never reads them. Stripped SSA is outside thessa.Verifycontract;program.Verifystill checks the emitted bytecode.The JIT tiers do not use
SSAPass, so they keep their states.Known behaviour change: when O3 inlines a call, it also removes that call's frame and stack use. A frame or stack limit that was reached only at that call no longer traps. A test pins this, and
docs/pass-system.mddocuments it.Evidence
All 29 kernels give the same results as O0 at O1, O2 and O3, on both the threaded and the jit backends.
Threaded, O3 vs O0. Each run is the min over interleaved repeats; the table shows the median of 3 runs.
Every other kernel is 1.00 ±0.02.
JIT, O3 vs O0.
The rest are within noise. When re-run, i64-wide-fib reads 0.92–0.93 and spectral-norm reads 0.85–0.97 on both builds, so I treat both rows as noise.
Tests were written red first, and mutation checks cover each new rule.
Validation
go test ./internal/... ./optimize ./interp ./programmake check(pre-commit hook)git diff --checkDocs
docs/pass-system.md: covers inlining in the bytecode path, the trapless rule and the removed call frame,StripPass, and DCE param pruning.Review
An adversarial Opus review found no CRITICAL issues. The second commit fixes both MEDIUM and all LOW findings.
🤖 Generated with Claude Code