Skip to content

internal/rewrite: make the overlap check small enough to inline - #18

Open
thesyncim wants to merge 2 commits into
tune-full-vector-loopfrom
inline-overlap-check
Open

thesyncim wants to merge 2 commits into
tune-full-vector-loopfrom
inline-overlap-check

Conversation

@thesyncim

@thesyncim thesyncim commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

The change is the first commit; the second only regenerates the goldens.

_loopvecOverlap took the windows as ...int, and with that its inlining cost was 114, over the budget of 80:

cannot inline _loopvecOverlap[go.shape.float32]: function too complex: cost 114 exceeds budget 80

So every rewritten loop that touches two slices makes a real call per pair before it starts, which takes about as long as a 64-element loop.

It now takes the four bounds as plain ints (a whole slice is 0, len(s)) and inlines at cost 55. The comparison is the same.

On an M4 Max, on top of #17: AddFloat32s/64 goes from 9.9 to 8.1 ns, AxpyFloat32s/64 from 10.3 to 8.0, ClampInt32s/64 from 8.3 to 6.9. Larger sizes don't notice.

Every rewritten loop with two or more slices calls _loopvecOverlap for
each pair before it runs. The helper took the windows as ...int and
inlining it cost 114, over the compiler's budget of 80, so each call was
a real call: AddFloat32s made two before it loaded anything, which for
a short loop costs about as much as the loop.

The helper now takes the windows as four plain arguments, and a whole
slice is passed as 0 and its length. It inlines (cost 55), and the
comparison is the same.
Regenerated with make test-update. The -d scripts (flag_diff.txt,
readme_patterns.txt) also check the size of the generated hunk, which
shrinks by six lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant