[flang-commits] [flang] [mlir] Fixing miscompilation with OMP synchronization at higher optimizations (PR #202258)
via flang-commits
flang-commits at lists.llvm.org
Thu Aug 13 21:21:33 PDT 2026
Ritanya-B-Bharadwaj wrote:
> @Ritanya-B-Bharadwaj I think rather than removing the noalias attribute in the presence of synchronization constructs, we should instead (a) enforce memory ordering imposed by explicit or implicit flushes and (b) prevent movement of OpenMP atomic accesses to dummy arguments (without the VALUE attribute) across procedure calls.
For (a), I kept `noalias` and instead pin the dummy args at each flush point with a small compiler barrier, so the sync calls can't be treated as if they don't touch the args. It kicks in at `barrier`, `critical`, `ordered`, and the end-barrier of `single`/`sections`/`wsloop` (skipped when there's `nowait`), plus explicit `flush(list)`, and it fixes the repro. The load now stays inside critical at `-O2`.
For (b), I did look into the atomics part, but I couldn't actually get an atomic access to move across a call. With or without `noalias`, the atomic loads and stores stay ordered around opaque calls at `-O2`, so it looks like LLVM already handles that one and I left it out. Let me know if you have a case where it breaks and I'll add it.
https://github.com/llvm/llvm-project/pull/202258
More information about the flang-commits
mailing list