Repository navigation
Conversation
#1424) flowc_cgen_loop_omp_safe accepted any body of indexed stores and reductions, and the pragma path then promised the C compiler that iterations are independent. With two pointer parameters that are shifted views of one buffer (dst = src + 1) the scalar loop is a recurrence; GCC 15 at -O3 vectorized it under ivdep and the program got a different result. flowc_cgen_loop_mem_independent now also requires every store to be base[i] with i the loop counter, store bases to be one name or proven disjoint (flowc_region_disjoint, the #1417 rule), and every indexed read to be a store base at i or proven disjoint from all store bases, with no reads through *p. Otherwise only the clang hint is emitted, and clang keeps its runtime alias checks. The same check covers rotated whiles. tests/cgen/for_simd_pragma_alias fails on the previous compiler, which emitted both pragmas; its C, built with gcc-15 -O3, exits 1.
… check (#1424) A parameter emitted restrict is proven disjoint from every other pointer parameter at every call site, so a loop over two such parameters keeps OpenMP simd and GCC ivdep (noalias_vectorize).
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.
Fixes #1424.
flowc_cgen_loop_omp_safeaccepted any body of indexed stores and reductions, and the pragma path then told the C compiler that iterations are independent (#pragma omp simd,#pragma GCC ivdep). With two pointer parameters that are shifted views of one buffer (dst = src + 1) the scalar loop is a recurrence. GCC 15 at -O3 vectorized it under ivdep and the program got a different result.The pragmas are now emitted only when
flowc_cgen_loop_mem_independentalso holds:base[i]withithe loop counter;i, or proven disjoint from every store base; no reads through*p.Disjoint means
flowc_region_disjoint(the #1417 rule), or two different parameters where #731 proved one of them disjoint from every other pointer parameter at all call sites (it is emittedrestrict). Otherwise only the clang hint is emitted; clang keeps its runtime alias checks. Rotated whiles from #1363 use the same check.Proof: tests/cgen/for_simd_pragma_alias fails on main (both pragmas emitted). Its C, built from main's flowc with gcc-15 -O3, exits 1; built from this branch, it exits 0. At -O2 GCC does not vectorize that loop, so default builds were not affected;
CFLAGS=-O3builds were.Gates (macOS arm64): cgen goldens 138/0 (noalias_vectorize and for_simd_clip keep their pragmas through the restrict proof), test-lang, test-runtime, simd_asm 2 passed / 2 skipped, self_host_full, roundtrip. tests/cli fails only jit_hello and test_mlir, as on main here.
Risk: GCC and OpenMP builds lose the independence hint on loops over unproven pointer parameters; they keep their own dependence analysis.