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

Fabian Ritter via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 07:28:49 PDT 2026


================
@@ -4057,12 +4057,18 @@ Given that definition, R{sub}`byte` is defined as follows:
 -  Otherwise, if R{sub}`byte` may see exactly one write,
    R{sub}`byte` returns the value written by that write.
 -  Otherwise, if R is atomic, and all the writes R{sub}`byte` may
-   see are atomic, it chooses one of the values written. See the {ref}`Atomic
+   see are atomic, and R and the writes all access the exact same set of
+   bytes, it chooses one of the values written. See the {ref}`Atomic
    Memory Ordering Constraints <ordering>` section for additional
    constraints on how the choice is made. Targets may impose additional
    requirements on R and the writes it may see based on their `syncscope`.
 -  Otherwise R{sub}`byte` returns `undef`.
 
+Defined atomic accesses cannot tear: Two byte subaccesses R{sub}`byte1`,
+R{sub}`byte2` of an atomic read R cannot read from different atomic
+writes W{sub}`1`, W{sub}`2` if both read subaccesses, R{sub}`byte1`,
----------------
ritter-x2a wrote:

No, that breaks the intended meaning: if Rbyte1 and Rbyte2 may not both see both writes W1 and W2, the read subaccesses don't have to read from the same write. For example:
```
S1: store atomic to bytes {0, 1, 2, 3} starting at address p
S2: store atomic to bytes {0, 1} starting at address p
L: load atomic from bytes {0, 1, 2, 3} starting at address p
```
These three operations are in a single thread, so they are in happens-before. `L` should be allowed to read bytes 0, 1 from `S2` and bytes 2, 3 from `S1`.

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


More information about the llvm-commits mailing list