reversed-stride in WENO7 coefficients (amdflang 23.2.x false-nuw)#1660
Merged
Conversation
…tup (amdflang 23.2.x false-nuw miscompile, flang PR #184573 / fix #198014)
Contributor
There was a problem hiding this comment.
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 explicitw(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 explicity(1:4)element-wise assignments. - Added in-code comments documenting why reversed-stride sections must not be reintroduced (compiler correctness rationale).
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
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 — likes_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
-O3: all fourweno_order=7golden tests (1D/2D/3D + wenoz/mapped) fail before this change (abs 2.1e-4) and pass after it../mfc.sh precheckclean.