Repository navigation
Conversation
This was referenced Oct 6, 2026
godofecht
added a commit
that referenced
this pull request
Oct 7, 2026
#pragma omp simd and GCC ivdep tell the C compiler that iterations are independent. An indexed store does not prove that on its own: dst may be src + 1. A loop body now gets them only when it is one statement that is either a reduction or a store dst[i] = e where the noalias analysis made dst restrict (#731) and e reads dst only at [i]. A reduction whose other operand reads the accumulator (acc = acc + acc * 2) is a recurrence and is no longer treated as a reduction. Other loops keep the clang vectorize request. flowc_cgen_assign_is_index_store is removed as unused. Carried from the SIMD half of the original #1416 branch; its copy half landed as #1417.
godofecht
force-pushed
the
fix/739-simd-dependence-gates
branch
from
October 7, 2026 12:15
05bfb5c to
6d5d9c3
Compare
godofecht
marked this pull request as ready for review
October 7, 2026 12:15
Contributor
Author
|
Note from the merge train: #1363 (remaining SIMD lowering) merged as e2205a7. It adds the vector_size kernels, select-converted ifs and while-to-for rotation in compiler/src/cgen.flow, with the #1417 overlap rule applied to kernels and span copies. Please rebase this draft's for_simd_dependence and for_simd_proven_reduction work onto it. |
#pragma omp simd and GCC ivdep tell the C compiler that iterations are independent. An indexed store does not prove that on its own: dst may be src + 1. flowc_cgen_loop_omp_safe now accepts a body of `let` statements followed by one statement that is either a reduction whose accumulator no `let` reads, or a store or select `if` into dst[v] where the noalias analysis made dst restrict (#731) and every expression reads dst only as dst[v]. A reduction whose other operand reads the accumulator (acc = acc + acc * 2) is a recurrence and no longer counts. The rotated while loops from #1363 use the same predicate for their ivdep, and flowc_cgen_body_omp_safe_skip is removed. Other loops keep the clang vectorize request. Carried from the SIMD half of the original #1416 branch; its copy half landed as #1417.
godofecht
force-pushed
the
fix/739-simd-dependence-gates
branch
2 times, most recently
from
October 7, 2026 13:19
6d5d9c3 to
7be7ea4
Compare
Contributor
Author
|
Overlap note: #1433 (mine) fixed #1424 the same way, so I am closing it in favour of this PR, which also covers the reduction case. Two things from it that may be worth carrying here:
Please add |
godofecht
added a commit
that referenced
this pull request
Oct 7, 2026
#pragma omp simd and GCC ivdep tell the C compiler that iterations are independent. An indexed store does not prove that on its own: dst may be src + 1. flowc_cgen_loop_omp_safe now accepts a body of `let` statements followed by one statement that is either a reduction whose accumulator no `let` reads, or a store or select `if` into dst[v] where the noalias analysis made dst restrict (#731) and every expression reads dst only as dst[v]. A reduction whose other operand reads the accumulator (acc = acc + acc * 2) is a recurrence and no longer counts. The rotated while loops from #1363 use the same predicate for their ivdep, and flowc_cgen_body_omp_safe_skip is removed. Other loops keep the clang vectorize request. Carried from the SIMD half of the original #1416 branch; its copy half landed as #1417.
Contributor
Author
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.
Part of #739. Does not close it. The #732 copy half of the original branch landed as #1417, so this PR carries only the SIMD half, rebuilt on main e2205a7 (after #1363).
Change
#pragma omp simdand#pragma GCC ivdeptell the C compiler that loop iterations are independent.flowc_cgen_loop_omp_safe, and the copy of its rule that #1363 added for rotated while loops (flowc_cgen_body_omp_safe_skip), granted them to any body of indexed stores, selectifs and recognized reductions. That is unsound in two ways:dst[i] = src[i] + 1withdst = src + 1carries a value from one iteration to the next.acc = acc + acc * 2matched the reduction pattern although its other operand reads the accumulator, so it gotreduction(+:acc).Now one predicate serves both loop forms. A body qualifies when it is
letstatements followed by one statement that is either:lets do not read the accumulator, orifintodst[v], wherevis the loop variable, the noalias analysis ([Performance #727] Emit proven noalias/restrict information in C and MLIR backends #731) madedstrestrict, and every expression in the body readsdstonly asdst[v].Other simple loops keep the clang vectorize request, which leaves the dependence check to the C compiler. Rotated while loops still never get OpenMP simd, as #1363 set.
flowc_cgen_body_omp_safe_skipis removed. CHANGELOG entry added.Not carried:
tests/native/copy_overlap_semantics.c, because main has no runner fortests/native/.Related and not changed here: #1363's
vector_sizekernels and span-copymemmovemake their own aliasing assumptions; they are worth a separate review against the same rule.Evidence
for_simd_dependence(shifted pointers plus the recurrence),for_simd_recurrence(the recurrence alone),for_simd_proven_reduction(a plain sum keepsreduction(+:total)).for_vectorize_pragma.expectupdated. Before this changefor_simd_dependenceandfor_vectorize_pragmafail (unexpected: #pragma omp simd,unexpected: #pragma GCC ivdep), and the old compiler emits#pragma omp simd reduction(+:acc)and#pragma GCC ivdepfor the recurrence.noalias_vectorize,for_simd_hot_loops,for_simd_clipandfor_simd_whilepass unchanged.flowc: PASS.bootstrap_from_c.sh --regen: fixed point at gen3;--verify: PASS.roundtrip.flow: ALL PASS. Bootstrap regenerated in its own commit../flow tool tests/cgen/run.flow: 140 passed, 0 failed../flow tool tests/scripts/simd_asm.flow: 2 passed, 2 skipped../flow test-lang274/0,./flow test-runtime34/0,./flow tool tests/cli/run.flow152 passed, 2 failed (jit_hello,test_mlir: golden drift on main).self_host_full.flowfails here withgen1.c != gen2.c(thevector_sizepreamble and someTOK_*constants). It fails the same way on main e2205a7 with no change, so it is a baseline failure from cgen: remaining SIMD lowering for hot C loops (#739) #1363.Merge note:
cgen.flowmerges cleanly with #1414; only the generated bootstrap files conflict, so the second to land needs its own regeneration.