Repository navigation
perf(optimize): give homed references their proven type, dup adjacent uses - #324
Merged
Merged
Conversation
… uses At O3, fannkuch still ran 5x slower under the JIT: a homed array ref got an `any` local, because SSA refs carry no static type, and the JIT and threaded fusion key on declared slot types. closure-counter lost 14% to a value homed only because two adjacent ops consumed it. - A homed reference's local takes the type its definition guarantees: the slot type of a local, global or upvalue load, a constant's type, or the common type of a block param's incoming values; else the type of the slots it is stored to when every such store is in its defining block ahead of every other use; else `any`. - A typed reference slot is reloaded rather than teed, so the reload carries the declared type. - A value whose uses in its own block consume it in turn is duplicated instead of homed, except ahead of an op that traps or enters a frame. 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 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.
Problem
After #323, two kernels were still well below O0 at O3:
[]i32ref got ananylocal, because SSA refs carry no static type. The JIT and threaded fusion key on declared slot types. Separately, thelocal.teeafterarray.slicekept an untyped value on the stack, so the JIT could not typearray.get.Change (
internal/transform/emit.go)Proven ref types. A homed reference's local takes the type its definition guarantees, checked in this order:
any.emitnow receives the source function, so it can read the capture types.No tee into typed ref slots. A typed ref slot is written and then reloaded, so the reload carries the declared type.
anyslots still tee.dup. A value whose uses in its own block consume it in turn is duplicated instead of homed. This is skipped ahead of an op that traps or enters a frame. A wrong placement fails the walk and falls back to homing.
docs/pass-system.md(Bytecode) updated.Evidence: O3 speed vs O0 (local, min-of-runs)
Every result matches O0. CI's benchmark A/B does not run the optimizer.
Tests (
TestSSAPass_Run), red first[]i32local, with noanylocal and no tee.any: red under "take the first incoming type".any: red under "take the first store's type".struct{f64}slot only on a branch that does not run. It must keep its capture type and return 41, not trap.Review
Two Opus rounds.
type mismatchwhere O0 returned 41. Fixed: the definition type wins, and stores count only in the defining block ahead of every other use.fusion.md), and the optimizer must only repair handlers.Not in this PR. It already fails at main, so it is a follow-up:
array.sliceof a[]i8) homed asanyand then stored to a[]i8global failsprogram.Verify, although the input verified.Validation
go test ./internal/transform ./optimize ./interpgo test -race ./internal/transform -run TestSSAPass_Runmake checkgit diff --check🤖 Generated with Claude Code