Repository navigation
perf(jit): inline pure scalar leaf callees at the optimized tier - #307
Merged
Merged
Conversation
InlinePass replaces a CALL of a statically resolved pure scalar leaf (no call, handler, capture, write or allocation; scalar params, locals and results without i64 or refs; at most 32 instructions; no backward branch) with the callee's promoted SSA body. Every state in the body is the CALL's own, so a deopt resumes the interpreter at the CALL and re-runs the pure callee unobserved; a feedback guard stays ahead of the body. It runs only for the Optimized tier, ahead of O3. A bridge or callout runs the opcode at its state's IP, so exit() now requires that opcode to equal the exiting op's (compile.ErrInlined); Compile retries once without inlining when an inlined op would bridge. Refs #239 Co-Authored-By: Claude Opus 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 9, 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
Step 5 (v1) of the #239 plan. spectral-norm's inner loops call a small non-recursive
func(i32, i32) f64n² times through a native call.InlinePass(internal/transform/inline.go, Optimized tier only, ahead of O3) replaces aCALLof a statically resolved callee that is a pure scalar leaf (leaf: no call, handler, capture, write or allocation; scalar params/locals/results, i64 and refs excluded; ≤ 32 instructions; no backward branch) with the callee's promoted SSA body, spliced through the rebuilder (returns jump to a join carrying the results).exit()now requires that opcode to equal the exiting op'sCode(compile.ErrInlinedotherwise). An inlined op the machine declines (e.g.f64.rem) would otherwise run the CALL instead;Compileretries once without the inline pass. Three hand-built tests whose states named a different opcode were corrected; the full suite shows the check never fires without inlining.pass-system.md(InlinePass),jit-internals.md(bridge invariant and retry).Evidence
TestNewInlinePass: straight-line and forward-branch leaves inlined with every body op on the CALL's state; call kept for ref param, global write, nested call, loop, too large, handlers, captures.TestLower"rejects a bridge whose state names another opcode";TestCompile"inlines a leaf callee at the Optimized tier only" and "compiles again without inlining when an inlined operation would bridge" (red with the retry disabled).TestWithThreshold"runs a call of a leaf callee as threaded does": direct and guarded callees, divisors including 0 (division-by-zero error equals threaded).go test ./internal/... ./interp,make check,git diff --check: pass.Found along the way, on main without this change: #306 (wrong JIT result after a speculated indirect callee changes and traps). The guarded-callee swap case is therefore not in this PR's parity test.
Refs #239
🤖 Generated with Claude Code