[llvm-dev] Nontemporal memory accesses and fences
Cranmer, Joshua via llvm-dev
llvm-dev at lists.llvm.org
Tue Apr 28 14:42:14 PDT 2020
The current specification of the behavior of the !nontemporal attribute in LLVM, and the __builtin_nontemporal_* functions in Clang, is rather spartan and underspecified. In effect, it says the following things:
* Atomic !nontemporal has no defined semantics
* !nontemporal may use special instructions to save cache bandwidth, such as "MOVNT" on x86.
What is crucially lacking from this specification is its effects in relation to other memory ordering constructs, namely fences. In lieu of text to the contrary, one could reasonably come to the conclusion that this code should be sufficient to generate correctly working code:
store i64 %x, i64* %addr, !nontemporal !100
But on x86 today, it does not: the first store is lowered to a MOVNT, while the fence release is lowered to a compiler-only memory barrier instead of an SFENCE (as regular load/store/atomicrmw operations already have these operations built into their execution semantics). So the fence instructions appear to be lowered with the expectation that nontemporal instructions do not exist, which is not implied by the language reference.
I've been pointed to an earlier thread (https://lists.llvm.org/pipermail/llvm-dev/2016-January/093912.html) that suggests an introduction of nontemporal-specific fences, but there appears to have been no effort to actually push this into LLVM. What's the current status of this work, and what is the right way to move forward and clarifying the semantics of !nontemporal with respect to threads.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev