Skip to content

reversed-stride in WENO7 coefficients (amdflang 23.2.x false-nuw)#1660

Merged
sbryngelson merged 4 commits into
MFlowCode:masterfrom
sbryngelson:weno-scalarize-slices
Jul 21, 2026
Merged

reversed-stride in WENO7 coefficients (amdflang 23.2.x false-nuw)#1660
sbryngelson merged 4 commits into
MFlowCode:masterfrom
sbryngelson:weno-scalarize-slices

Conversation

@sbryngelson

Copy link
Copy Markdown
Member

What

Rewrites the five reversed-stride array sections in the WENO7 branch of s_compute_weno_coefficients (the only negative-stride sections in the codebase) as explicit element-wise assignments. Values are bit-identical — array subtraction is element-wise — so there are no golden-file changes.

Why

amdflang from AMD's AFAR drops 23.2.0/23.2.1 carries flang commit llvm/llvm-project#184573 ("Apply nusw nuw flags on array_coor gep's") without its correctness fix llvm/llvm-project#198014 (merged upstream 2026-05-20, fixes llvm/llvm-project#197393). In that window, flang stamps unsigned-no-wrap (nuw) claims on the address arithmetic of descriptor-array accesses. For negative-stride sections — like s_cb(i+4:i-3:-1) here — those claims are false, i.e. poison, and the optimizer legally miscompiles: the WENO7 coefficient tables come out slightly wrong, which the ill-conditioned WENO weights amplify to abs 2.1e-4 density errors at shock fronts (weno7 golden tests fail on gfx90a builds at -O2/-O3; correct on drop 23.1.0).

Reported to AMD with full root-cause evidence: ROCm/llvm-project#3471.

Element-wise assignment lowers to plain indexed accesses whose no-wrap claims are true, removing the miscompile at its source. Each site carries a comment so the slices don't get "cleaned up" back into reversed sections. Beyond the specific bug, this makes the one-time setup code robust against this whole class of section-lowering issues on any compiler, at zero cost (init-only code, value-identical).

Testing

  • amdflang AFAR 23.2.0, gfx90a OpenMP offload, -O3: all four weno_order=7 golden tests (1D/2D/3D + wenoz/mapped) fail before this change (abs 2.1e-4) and pass after it.
  • Values are bit-identical by construction; CI validates the four gated compilers.
  • ./mfc.sh precheck clean.

…tup (amdflang 23.2.x false-nuw miscompile, flang PR #184573 / fix #198014)
Copilot AI review requested due to automatic review settings July 20, 2026 01:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the WENO7 coefficient setup in src/simulation/m_weno.fpp against an amdflang 23.2.x optimizer miscompile triggered by negative-stride array sections, by replacing the affected reversed-stride descriptor-array sections with equivalent explicit element-wise assignments.

Changes:

  • Replaced the single reversed-stride w = s_cb(i+4:i-3:-1) - s_cb(i) assignment with explicit w(1:8) element-wise assignments to avoid negative-stride section lowering.
  • Replaced four reversed-stride y = ... - ... assignments (used for left-side polynomial coefficient setup) with explicit y(1:4) element-wise assignments.
  • Added in-code comments documenting why reversed-stride sections must not be reintroduced (compiler correctness rationale).

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.49%. Comparing base (0857ace) to head (72a483d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1660      +/-   ##
==========================================
+ Coverage   59.46%   59.49%   +0.03%     
==========================================
  Files          83       83              
  Lines       21170    21189      +19     
  Branches     3135     3135              
==========================================
+ Hits        12588    12607      +19     
  Misses       6476     6476              
  Partials     2106     2106              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson sbryngelson changed the title fix(weno): scalarize reversed-stride sections in WENO7 coefficient setup (amdflang 23.2.x false-nuw miscompile) reversed-stride in WENO7 coefficients (amdflang 23.2.x false-nuw) Jul 21, 2026
@sbryngelson
sbryngelson merged commit 30df8e5 into MFlowCode:master Jul 21, 2026
87 checks passed
@sbryngelson
sbryngelson deleted the weno-scalarize-slices branch July 21, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Flang] Incorrect results from ASSOCIATE constructs with -O2 or higher

2 participants