Skip to content

feat: Add compiler performance remarks (#744) - #1309

Merged
godofecht merged 18 commits into
mainfrom
perf-remarks-12250665050446778278
Oct 4, 2026
Merged

godofecht merged 18 commits into
mainfrom
perf-remarks-12250665050446778278

Conversation

@godofecht

@godofecht godofecht commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Add opt-in compiler performance remarks explaining missed optimizations in idiomatic Flow. This surfaces optimization facts the C generator already computes without requiring the developer to read generated C or assembly.

It covers:

  • span bounds checks retained
  • loop vectorization skipped

Resolves #744.


PR created automatically by Jules for task 12250665050446778278 started by @godofecht

…s in idiomatic Flow

Adds `FLOWC_PERF_REPORT` opt-in compiler mode which surfaces optimization decisions directly inside the emitted C code as `/* perf[...] ... */` comments.

This covers three codegen areas:
- `span-bounds-check-retained`: an index into a span keeps its bounds check if the index isn't structurally proven via an ascending loop bound.
- `f32-math-widened-to-f64`: an f32 argument to a standard libm function causes the argument to be widened to double precision.
- `loop-not-vectorized`: a for loop with a step stays scalar because its body has a function call or control flow (is not "simple").

Testing:
- `tests/cgen/perf_remarks.flow` with an `.expect` that invokes `FLOWC_PERF_REPORT=1` validates the output.

Co-authored-by: godofecht <[email protected]>
@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 and others added 17 commits October 3, 2026 19:36
The main merge left a stale f32-math-widened-to-f64 remark in
flowc_stage_a.c that compiler/src no longer emits. Regen to the
fixed point so the self-host roundtrip matches compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
…050446778278

Bring in #1278 (complex scaling / bounds elision) and #1297 (vgpu
conformance runner). Keep FLOWC_PERF_REPORT remarks in cgen.flow.
Bootstrap C is left at the previous fixed point and regenerated next.

Co-authored-by: Abhishek Shivakumar <[email protected]>
The merge of #1278/#1297 left the previous fixed point. Self-emit
until gen1 and gen2 agree so flowc_stage_a.c matches compiler/src.

Co-authored-by: Abhishek Shivakumar <[email protected]>
…050446778278

Bring in #1302 (incremental AST caching). Keep FLOWC_PERF_REPORT remarks
in cgen.flow. Bootstrap C is left at the previous auto-merge and
regenerated next.

Co-authored-by: Abhishek Shivakumar <[email protected]>
The auto-merged flowc_stage_a.c was already the gen2 fixed point
(perf remarks plus #1302 parse cache). Rebuild the checked-in
binary so it matches that C.

Co-authored-by: Abhishek Shivakumar <[email protected]>
@godofecht
godofecht merged commit 64db9fb into main Oct 4, 2026
35 checks passed
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Bring the branch onto 64db9fb so #1309 compiler performance remarks
land under the math-intrinsic *f selection. cgen.flow auto-merged both
sides. Keep main's bootstrap C here; regenerate after compiler/src is
settled.

Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor Bot pushed a commit that referenced this pull request Oct 4, 2026
Reach a fixed point after merging compiler performance remarks (#1309)
onto the f32/c64 math-intrinsic *f selection. Fixed point at gen2.

Co-authored-by: Abhishek Shivakumar <[email protected]>
godofecht added a commit that referenced this pull request Oct 4, 2026
…1317)

* Fixes #734: Audit precision promotion and math intrinsic selection across f32/f64/c64/c128

This commit ensures that single-precision and complex math functions correctly invoke their precision-accurate intrinsic equivalents (e.g., `sqrtf` and `cexpf`) rather than silently promoting arguments to double precision or double precision complex numbers in C output.

- `cgen.flow`: Added checks inside `flowc_cgen_emit_expr_inner` for `f32` and `c64` types. Re-routes functions like `sqrt`, `sin`, `fabs`, and `cabs` to their `*f` counterparts.
- `mlirgen.flow`: Handled the mappings in `mlg_libc_sig` to emit `MT_F32` and `MT_C64` results for these functions on specific inputs.
- Verified test semantics with `NaN` and `Inf` using the new `test_f32_c64_math_semantics.flow` language tests.
- Recreated generated `flowc_stage_a.c` to reach the fixed point and integrated performance microbenchmarks (`math_loop.flow`).

Co-authored-by: godofecht <[email protected]>

* test: cover f32 libm lowering

* test: add f32 math intrinsic regression

* test: add f32 math intrinsic expectations

* fix: select *f math from callee f32/c64 signature

Expression types only recover idents, so fabs(-x) and exp(0.1) never
selected the single-precision libm names. stdlib math is declared f32,
so read the callee parameter type as well. That is the self-host cgen
golden failure on #1317.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: pick *f math from imported stdlib float signatures

Bundle emit keeps each module in its own arena, so fn_id never sees
stdlib/math.flow. Read the cross-module sig table (float / c64) and
walk unary minus on the first argument. That is what the #1317 cgen
goldens actually compile.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after math intrinsic merge

Checked-in Stage-A C must match compiler/src. The previous #1317
bootstrap predates main at 29f4d86 and the imported-signature *f
selection. Fixed point at gen2.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after math intrinsic merge

Checked-in Stage-A C must match compiler/src. The previous #1317
bootstrap predates main at c9ee445 (#1278 codegen taxes, #1297 vgpu)
and the imported-signature *f selection. Fixed point at gen2.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after math intrinsic merge

Reach a fixed point after merging incremental AST caching (#1302)
onto the f32/c64 math-intrinsic cgen changes.

Co-authored-by: Abhishek Shivakumar <[email protected]>

* fix: regenerate bootstrap C after math intrinsic merge

Reach a fixed point after merging compiler performance remarks (#1309)
onto the f32/c64 math-intrinsic *f selection. Fixed point at gen2.

Co-authored-by: Abhishek Shivakumar <[email protected]>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: godofecht <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
@godofecht
godofecht deleted the perf-remarks-12250665050446778278 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.

[Performance #727] Add compiler performance remarks explaining missed optimizations in idiomatic Flow

2 participants