Repository navigation
cgen: portable SIMD-aware lowering for hot C loops - #1339
Merged
Merged
Conversation
godofecht
marked this pull request as ready for review
October 4, 2026 18:49
Emit compiler-recognizable C for the #739 numeric loop forms on the C backend: OpenMP simd (with reduction clauses) when available, clang/GCC vectorize hints otherwise, and memmove for contiguous copies. Stepless `for i in 0 to n` now gets the same treatment as stepped loops. Scalar loop-carried updates stay off the OpenMP/ivdep path. Co-authored-by: Abhishek Shivakumar <[email protected]>
The #739 skip-test no longer includes the stepless zeroing loop, so its recorded normalized-MLIR digest in compiler/fixtures/mlir/corpus.txt needed a parity_mlir-style re-record of that one program. Co-authored-by: Abhishek Shivakumar <[email protected]>
Fixed point of compiler/src after rebasing the #739 SIMD slice onto main's record-update copy elision. bootstrap_from_c.sh --verify holds. Co-authored-by: Abhishek Shivakumar <[email protected]>
cursor
Bot
force-pushed
the
cursor/cgen-portable-simd-hot-loops-92ec
branch
from
October 4, 2026 19:40
f55ade5 to
51b0800
Compare
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
#1339 added for_simd_carried and for_simd_hot_loops. Record their normalized MLIR via parity_mlir.flow --record. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
7 of 8 tasks
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Fixed point of compiler/src after rebasing the #740 memory profiler onto main's SIMD C lowering (#1339). bootstrap_from_c.sh --verify holds. Co-authored-by: Abhishek Shivakumar <[email protected]>
8 tasks done
cursor Bot
pushed a commit
that referenced
this pull request
Oct 4, 2026
Rebased onto main (#1339). Bootstrap C now includes both portable SIMD-aware loop lowering and FLOWC_PROFILE phase timers. Co-authored-by: Abhishek Shivakumar <[email protected]>
7 of 8 tasks
godofecht
added a commit
that referenced
this pull request
Oct 4, 2026
…1340) * feat: add compiler-derived type identity and alignof (#775) Expose type_family_id<T>(), type_schema_id<T>(), type_transport_safe<T>(), and alignof<T>() as compile-time builtins so libraries can stop assigning manual type keys. Family and schema IDs are target-independent FNV-1a 64 digests of a versioned canonical description; size and alignment stay the target ABI. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after type identity builtins Co-authored-by: Abhishek Shivakumar <[email protected]> * test: compare compiled type IDs without flow-run banners Co-authored-by: Abhishek Shivakumar <[email protected]> * test: use let mut for C compiler selection in type identity check Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: include type_id in cgen single-module roundtrip compile_module cgen force-includes only listed dep headers, so the new type-identity helpers were undeclared. Emit type_id first, then -include it for cgen, and link it with the frontend objects. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after merging copy elision Merged cgen now includes both type identity builtins and record-update copy elision. Rewrite the checked-in bootstrap C to that fixed point. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: re-record parity_mlir corpus after type identity test_typecheck_overload_integration.flow imports typecheck.flow, whose new type-identity builtins changed the normalized MLIR digest. Refresh via parity_mlir.flow --record (also records newly accepted programs, including test_type_identity.flow). Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: regenerate bootstrap C after merging portable SIMD Merged cgen now includes type identity builtins and SIMD-aware loop lowering. Rewrite the checked-in bootstrap C to that fixed point. Co-authored-by: Abhishek Shivakumar <[email protected]> * fix: record parity_mlir digests for SIMD loop fixtures #1339 added for_simd_carried and for_simd_hot_loops. Record their normalized MLIR via parity_mlir.flow --record. Co-authored-by: Abhishek Shivakumar <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]>
8 tasks done
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.
Intent
Part of #739 (parent #727). Related: #665, #666, #733, #751.
The production C backend still emitted scalar counted loops for the usual numeric form
for i in 0 to n. Only stepped straight-line loops got clang/GCC vectorize hints, so stdlib kernels (scale_f32,sum_f32,dot_f32, copies) never advertised SIMD to the C compiler. Jules PR #1333 is an empty publish of the same session and is left alone; #1280 merged only scratch C files at the repo root.This slice adds real flowc codegen:
#pragma omp simdwhen_OPENMPis defined, else clangloop vectorize/ GCCivdep.reduction(+:x)/(-:)/(*:)when the body isacc = acc ⊕ expr.memmovefor unit-stridedst[i] = src[i](pointer/array, not spans; keeps bounds checks when they would have fired).acc = acc * 10 + i) get only the clang hint, so OpenMP/ivdep do not promise independence.Scalar fallback is the same loop body; pragmas and
memmoveare optional C.Overlap check
Overlap / dependency notes: Open PR #1333 claims this issue but has 0 files changed — not revived. Merged #1280 did not change
compiler/src/cgen.flow. Rebased onto currentmain(includes #732 record-update copy elision).Evidence
Baseline before this change:
tests/cgen/for_vectorize_pragmapassed; steplessfor i in 0 to nhad no SIMD hints. Nomemmovecopy lowering.Targeted proof:
for_vectorize_pragma,for_vectorize_pragma_skip,for_simd_hot_loops,for_simd_carried,for_range_affine,perf_remarks,parallel_for_openmp,copy_elision,record_update)copy_elision5/5PATH=/tmp/nopy-mlir:$PATH ./flow tool compiler/scripts/parity_mlir.flow→ PASS (fixtures 23/23, corpus programs=2469 fail=0)./compiler/scripts/bootstrap_from_c.sh --verify→ PASSWhy that proof would detect the old failure: goldens require the new C hints/
memmove;parity_mlirnow has the updated corpus digest fortests/cgen/for_vectorize_pragma_skip.flow(the skip-test source droppedno_step).Repository gate(s) run: SIMD/copy-elision cgen subset,
parity_mlir(no-Python PATH shim),bootstrap_from_c.sh --verify.Generated/bootstrap state:
compiler/bootstrap/flowc_stage_a.cregenerated to the gen2 fixed point after the rebase.Risk
Generated C gains preprocessor-guarded pragmas and, for copies,
memmove. Compilers ignore unknown pragmas; results are unchanged for the scalar fallback.docs/project/Questions.mdupdated if this needs a language-design decision.Compatibility
docs/project/CHANGELOG.md.Remaining work for #739
Not claiming
Closes #739. Still needed for acceptance:for; span copies; branchy clip/min-max forms.Agent handoff
Cursor cloud agent. Do not merge.
Any remaining blocker is recorded in GitHub rather than only in local/session state.