[llvm] [RFC][LangRef] Specify that the accessed bytes of concurrent atomics must be either disjoint or the same (PR #204329)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 23 04:57:36 PDT 2026


gonzalobg wrote:

> This solution implies that transformations that merge adjacent atomic
loads/stores into wider atomic loads/stores are generally incorrect.

@ritter-x2a Fabian I agree with this assessment. @YonahGoldberg just added an `elementwise` modifier to `atomicrmw` in https://github.com/llvm/llvm-project/pull/189517 and we are planning to add it for load and store as well. 

With this extension, merging adjacent atomic load/stores of the same size into a vector `elementwise` atomic load/store is legal, enabling a backend of an architecture for which it is correct to lower these to a single wide atomic load/store.

However, the main reason we are pursuing `elementwise` for loads/stores is to enable the backend to split a wider vector load into smaller ones. I personally dislike requiring `elementwise` to enable merging of atomic loads/stores. It avoids having to extend the LLVM IR memory model for mixed-sized accesses, but if we wanted to merge loads/stores of different widths (e.g. i32, i16, i16), we'd need an even uglier hack. 

Long term I think we should figure out how to extend the LLVM IR memory model to support mixed-sized atomic accesses. This sounds like a pretty hard problem to me. I believe Test CO-MIXED-6 in [Flur et al, Mixed-Size Concurrency: ARM, POWER, C/C++11, and SC, POPL '17](https://www.cl.cam.ac.uk/~pes20/popl17/mixed-size.pdf) shows that to justify this optimization we'd probably need to allow a cycle in the union of coherence and program order :/ 

https://github.com/llvm/llvm-project/pull/204329


More information about the llvm-commits mailing list