<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<blockquote style="border-left: 3px solid rgb(200, 200, 200); border-top-color: rgb(200, 200, 200); border-right-color: rgb(200, 200, 200); border-bottom-color: rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of JF Bastien via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> Tuesday, April 28, 2020 4:54 PM<br>
<b>To:</b> Cranmer, Joshua <joshua.cranmer@intel.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Nontemporal memory accesses and fences</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">I see nontemporals as a nice builtin so you don’t have to hand-write the assembly. I don’t think existing hardware is consistent enough to allow us to expose nice semantics at a language
 or IR level, in the sense that we probably don’t want to define what happens if you step out of the comfortable uses for nontemporals (i.e. what happens when you start having temporality). A builtin pre / post fence seems fine to me, but that still leaves
 a gaping semantic hole… which I’m also fine with.
<div class=""><br class="">
</div>
<div class="">FWIW you have the same problem, somewhat worse, with some vector load / store instructions on some ISAs.</div>
</div>
</div>
</blockquote>
<div class=""><br>
</div>
<div class="">I was under the impression that we had decided to move forward with the fence, and it continues to make sense to me.</div>
<div class=""><br>
</div>
<div class=""> -Hal</div>
<div class=""><br>
</div>
<blockquote style="border-left: 3px solid rgb(200, 200, 200); border-top-color: rgb(200, 200, 200); border-right-color: rgb(200, 200, 200); border-bottom-color: rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);">
<div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">
<div class=""><br class="">
<div><br class="">
<div class="">On Apr 28, 2020, at 2:42 PM, Cranmer, Joshua <<a href="mailto:joshua.cranmer@intel.com" class="">joshua.cranmer@intel.com</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="x_WordSection1" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
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:</div>
<ul type="disc" class="" style="margin-bottom:0in; margin-top:0in">
<li class="x_MsoListParagraph" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
Atomic !nontemporal has no defined semantics</li><li class="x_MsoListParagraph" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
!nontemporal may use special instructions to save cache bandwidth, such as “MOVNT” on x86.</li></ul>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
 </div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
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:</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
 </div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
store i64 %x, i64* %addr, !nontemporal !100</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
fence release</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
 </div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
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.</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
 </div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
I’ve been pointed to an earlier thread (<a href="https://lists.llvm.org/pipermail/llvm-dev/2016-January/093912.html" class="" style="color:rgb(149,79,114); text-decoration:underline">https://lists.llvm.org/pipermail/llvm-dev/2016-January/093912.html</a>) 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.</div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span class="" style="font-size:9pt"> </span></div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<span class="" style="font-size:9pt">--<span class="x_Apple-converted-space"> </span></span></div>
<div class="" style="margin:0in 0in 0.0001pt; font-size:11pt; font-family:Calibri,sans-serif">
<i class=""><span class="" style="font-size:9pt">Joshua Cranmer</span></i></div>
</div>
</div>
</div>
<br class="">
</div>
</div>
</div>
</blockquote>
<div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">
<div class=""></div>
</div>
</div>
</body>
</html>