<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64521>64521</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Missing documentation on how nontemporal stores interact with concurrency primitives
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RalfJung
      </td>
    </tr>
</table>

<pre>
    The LLVM LangRef doesn't document how `!nontemporal` stores are intended to interact with concurrency primitives. The current interactions are extremely surprising, basically making `!nontemporal` stores even less ordered than "non-atomic" stores:
```
Thread A:
  store i32 %v, ptr %p, !nontemporal !13
 fence release
  // set some global flag (relaxed write)

Thread B:
  // wait till global flag is set (relaxed read)
  fence acquire
 %_0 = load i32, ptr %p, !noundef !11
```

According to all the usual concurrency rules, that last load must see the store. However, the way LLVM compiles this program on x86, it has a data race: the fences become NOPs and the relaxed accesses become regular MOV, so we end up with `MOVNT; MOV` in thread A, which the CPU is allowed to reorder -- meaning that thread B might see the flag write but then fail to see the data store!

In other words, `!nontemporal` violates TSO, but the compilation scheme LLVM (and everyone else) uses for release/acquire synchronization relies on TSO. Together this leads to rather unpredictable semantics.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVF1v6zYM_TXKC9HAlpvUffBDPxBsQ3t7cW_W14GWaVubLHmiHDf79YNk9wsohgFBYkfk0eEheZBZd5aoErtbsbvf4BR656sfaNrfJtttatecq2NP8PDw_AgPaLsf1ELjiK2QVwEap6aBbIDezSD2mZC5dTbQMDqPRuwz4OA8MaAn0DaQbaiB4NKzRxVg1qEH5ayavCerzjB6PeigT8RbiDcvB-EtQzu7wNFL8DSQOQNPfvSate2EvIMaWSs05gwD_qVt95-86EQWDDGD8w35SK5HC0JK6-wFBjdoJaRcw0VxI7J7kd1EyOWTXo-9J2zg5u0clgTQhQQhd6fIaww-Po_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