<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 25, 2016, at 11:05 AM, Zhuravlyov, Konstantin <<a href="mailto:Konstantin.Zhuravlyov@amd.com" class="">Konstantin.Zhuravlyov@amd.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">We believe that it would be best that this is added to the LLVM IR atomic memory instruction as fields on atomic instructions rather than using meta data.<br class=""><br class="">The reasoning is that this information is similar to other information that is represented as instruction fields. For example, the indication that memory operations are atomic rather than non-atomic, the memory ordering of atomics, and whether per-thread or system scope. In all these cases this information has a semantic meaning for the instructions that can be exploited by optimizations. Representing it as meta data would mean this information could be dropped making the optimizations impossible with very significant performance penalty.<br class=""><br class="">For example, if memory operations were not marked as being atomic, all memory operations would have to be generated as sequential consistent atomics at system scope. Although this "default" behavior is correct, it would not be very performant. Similarly, the memory ordering could use a "default" of sequentially consistent, which again is much less efficient than the weaker orderings. By analogy, the memory scope could also have a "default" of system scope, but that is also not performant when the scope is narrower.<br class=""><br class="">In all these cases this information changes the semantics of the instructions. It affects whether a program is undefined behavior. Using a "default" value leads to those same programs being treated as having defined behavior (for example by eliminating data races).<br class=""></div></div></blockquote><div><br class=""></div><div>It is not clear to me if there is any correctness issues to dropping metadata?</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Currently the atomic memory instructions have the own-thread/system recorded on the instruction which is a limited form of memory scope. The proposal is to replace this with a more general field that can have more than 2 values. Languages that do not use memory scopes can simply use the value corresponding to system scope.<br class=""><br class="">We understand that it is good to avoid adding information to LLVM instructions that is not primary, but in this case it seems that the atomicity, memory ordering and memory scope are all equally primary information that characterize the semantics of memory instructions.<br class=""><br class="">We have posted reviews that implement the proposal and invite everyone to discuss it:<br class=""><a href="http://reviews.llvm.org/D21723" class="">http://reviews.llvm.org/D21723</a><br class=""><a href="http://reviews.llvm.org/D21724" class="">http://reviews.llvm.org/D21724</a><br class=""></div></div></blockquote><div><br class=""></div><div>It seems you’re going back to integer, which I don’t really like for reasons mentioned earlier in this thread, and that I don’t feel you addressed here.</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">Thank you,<br class="">Konstantin<br class=""><br class=""><br class=""><br class="">-----Original Message-----<br class="">From: Tom Stellard [<a href="mailto:tom@stellard.net" class="">mailto:tom@stellard.net</a>] <br class="">Sent: Wednesday, June 22, 2016 4:51 PM<br class="">To: Pekka Jääskeläinen <<a href="mailto:pekka.jaaskelainen@tut.fi" class="">pekka.jaaskelainen@tut.fi</a>><br class="">Cc: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" class="">mehdi.amini@apple.com</a>>; Liu, Yaxun (Sam) <<a href="mailto:Yaxun.Liu@amd.com" class="">Yaxun.Liu@amd.com</a>>; Ke Bai <<a href="mailto:kebai613@gmail.com" class="">kebai613@gmail.com</a>>; Mekhanoshin, Stanislav <<a href="mailto:Stanislav.Mekhanoshin@amd.com" class="">Stanislav.Mekhanoshin@amd.com</a>>; <a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>; Tye, Tony <<a href="mailto:Tony.Tye@amd.com" class="">Tony.Tye@amd.com</a>>; Sumner, Brian <<a href="mailto:Brian.Sumner@amd.com" class="">Brian.Sumner@amd.com</a>>; Zhuravlyov, Konstantin <<a href="mailto:Konstantin.Zhuravlyov@amd.com" class="">Konstantin.Zhuravlyov@amd.com</a>><br class="">Subject: Re: [llvm-dev] Memory scope proposal<br class=""><br class="">+ Brian and Konstantin<br class=""><br class="">On Wed, May 18, 2016 at 11:18:53AM +0300, Pekka Jääskeläinen wrote:<br class=""><blockquote type="cite" class="">Hi all,<br class=""><br class="">On 02.05.2016 17:46, Tom Stellard via llvm-dev wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Why not going with a metadata attachment directly and kill the "singlethread" keyword? Something like:<br class=""><blockquote type="cite" class="">Something like:<br class=""><br class=""> cmpxchg i32* %addr, i32 42, i32 0 monotonic monotonic, 3, <br class="">!memory.scope{!42} cmpxchg i32* %addr, i32 42, i32 0 monotonic <br class="">monotonic, 3, !memory.scope{!43}<br class=""><br class="">...<br class=""><br class="">!42 = !{"singlethread"}<br class="">!43 = !{"L2"}<br class=""><br class=""><br class="">I also avoids manipulating/pruning the global map, and target won't depend on integer to keep bitcode compatibility.<br class=""><br class=""><br class=""></blockquote></blockquote>This seems like it will work assuming that promoting something like <br class="">"L2" to the most conservative memory scope is legal (this is what <br class="">would have to happen if the metadata was dropped). Are there any targets where this type of'<br class="">promotion would be illegal?<br class=""></blockquote><br class="">+1<br class=""><br class="">Sorry to enter this discussion so late, but in my opinion this is a <br class="">very good non-intrusive starting point solution.<br class=""><br class="">Implementing it as a MD with the assumption of there being a safe <br class="">conservative memory scope to fall back to (in case the MD gets <br class="">stripped off for some reason) converts it to a mere optimization hint <br class="">without the need to touch LLVM IR instruction semantics.<br class=""><br class="">Also, as it's only a MD, if we encounter a need to extend it later <br class="">towards a more integrated solution (or a mechanism to support targets <br class="">where this scheme is not feasible), we can more easily do so.<br class=""><br class="">BR,<br class="">--<br class="">Pekka<br class=""></blockquote></div></div></blockquote></div><br class=""></body></html>