Skip to content

Perf: move of a returned record update of a local base in MLIR (#696) - #1418

Merged
godofecht merged 5 commits into
mainfrom
perf-696-move-inference-mlir-14226189590247552527
Oct 7, 2026
Merged

godofecht merged 5 commits into
mainfrom
perf-696-move-inference-mlir-14226189590247552527

Conversation

@godofecht

@godofecht godofecht commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of #696. MLIR mirror of flowc_cgen_try_rupdate_return: return Name { ..base, f: v } with a local base inserts the listed fields into the base value and returns it, with no copy through a second alloca.

Merge-train rebase onto main 81ecf1e (50994e9):

  • The original fast path never ran: it checked for AST_RECORD_UPDATE, but a record update reaches the emitter as an AST_STRUCT_LIT with the base in c. With the check corrected, two defects showed, now fixed: struct locals are alloca-backed off wasm32, and the path read the SSA value, which a field store (p.x = a) leaves stale; and an unknown field walked off the field list. The base is loaded from its alloca when it has one, fields are validated before emitting, and the struct type must equal the return type.
  • Merge main into branch and resolve conflicts #1420 is not folded: against main it defines mlg_expr_uses_name, mlg_rupdate_values_use_name and mlg_try_rupdate_return a second time and reverts the README statistics.
  • New goldens: tests/mlir_commands mlir_record_update_return (fails on main, which emits the copy) and the parity fixture compiler/fixtures/mlir/record_update_return (run output 7 5 0 4; the 7 is the stored field). Two corpus digests move (tests/cgen/copy_elision.flow, tests/lang/test_copy_elision.flow).

Gates (macOS arm64): parity_mlir PASS, mlir_commands 88/0, cgen goldens, test-lang, test-runtime, self_host_full, roundtrip. corpus_parity --check reports 1016 < floor 1033 on Darwin, identical on main here. tests/cli fails only jit_hello and test_mlir, as on main.

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@godofecht
godofecht force-pushed the perf-696-move-inference-mlir-14226189590247552527 branch from d83e6c8 to 50994e9 Compare October 7, 2026 14:35
google-labs-jules Bot and others added 5 commits October 7, 2026 16:31
Rebased from d83e6c8 onto main without its bootstrap commit. #1420's
follow-up is not folded: against main it defines mlg_expr_uses_name,
mlg_rupdate_values_use_name and mlg_try_rupdate_return a second time and
reverts the README statistics.

Co-authored-by: godofecht <[email protected]>
The fast path checked for AST_RECORD_UPDATE, but a record update reaches
the emitter as an AST_STRUCT_LIT with the base in c (the marker kind
never appears there), so the path never ran. Matching the real shape
exposes two defects, fixed here: a struct local is alloca-backed off
wasm32, and the path read its SSA value, which a field store such as
p.x = a leaves stale; and an unknown field name walked off the field
list. The base is now loaded from its alloca when it has one, every
field is checked before anything is emitted, and the struct type must
equal the function's return type.
mlir_record_update_return returns Name { ..p, f: v } from a local base
after a field store to it. The golden has no copy through a second
alloca and reads the stored field; main's compiler fails it (it emits
the extract/insert copy and a second alloca).
…sion digests (#696)

compiler/fixtures/mlir/record_update_return is now a parity fixture
(run output 7 5 0 4). tests/cgen/copy_elision.flow and
tests/lang/test_copy_elision.flow return record updates of local bases,
so their recorded MLIR digests move; only those two corpus lines change.
@godofecht
godofecht force-pushed the perf-696-move-inference-mlir-14226189590247552527 branch from 50994e9 to 1049583 Compare October 7, 2026 15:31
@godofecht
godofecht merged commit f313b64 into main Oct 7, 2026
38 checks passed
godofecht added a commit that referenced this pull request Oct 7, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s, functions with a forward declaration or
an overload, keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
The pointer ABI no longer depends on w.sigs_len, which grows during
emission and let a prototype and its definition disagree.
godofecht added a commit that referenced this pull request Oct 7, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 7, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
godofecht added a commit that referenced this pull request Oct 8, 2026
Single-module functions that return a named struct take a hidden
`T* __flowc_sret` destination; in bundle mode (FLOWC_BUNDLE=1) the
callee keeps a local sret slot so the pointer ABI is not exposed across
modules. Record updates whose destination overlaps a source read go
through a temporary (overwrite dependence); others build in place.
The runtime profile and the #728 harness report copy_count (aggregate
copy operations) next to copies (bytes).

Rebased from PR #1367 onto current main. cgen conflicts with the span
data temps (#729/#1383) and the noalias clone flag (#731): the function
prologue emits the sret slot, then the span temps, then the body; the
buffer keeps na_clone, bounds_hi_* and sret. Doc and harness comment
conflicts keep both sides.

On rebase: `export function`s keep the value-return C signature (no
pointer sret), because a module compiled on its own (roundtrip.flow,
stage_a_self_emit) only sees that declaration; the PR as written failed
roundtrip with "too few arguments" in lexer_flowc.c. The record-update
MLIR goldens (fixture, corpus digests for the three copy-elision
programs, mlir_commands) are re-recorded on top of #1418; parity_mlir
runs all 24 fixtures through MLIR and they pass.
@godofecht
godofecht deleted the perf-696-move-inference-mlir-14226189590247552527 branch October 12, 2026 23:03
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