<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 31, 2016 at 6:36 PM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div><blockquote type="cite"><div>On May 31, 2016, at 6:28 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><div><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, May 31, 2016 at 6:11 PM Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On May 31, 2016, at 6:00 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote"><div dir="ltr">On Fri, May 27, 2016 at 8:43 AM Mehdi Amini via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On May 18, 2016, at 11:16 AM, Peter Collingbourne via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 17, 2016 at 6:46 PM, Chandler Carruth<span> </span><span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><div><div dir="ltr">On Tue, May 17, 2016 at 6:40 PM Peter Collingbourne via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 17, 2016 at 6:07 PM, Chandler Carruth<span> </span><span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>Thanks for the detailed write-up, and sorry to Rafael and Mehdi that it's on a new thread. =/</div><div><div><div><br></div><div dir="ltr">On Tue, May 17, 2016 at 5:59 PM Peter Collingbourne via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">pcc created this revision.<br>pcc added reviewers: rafael, joker.eph, chandlerc, majnemer.<br>pcc added a subscriber: llvm-commits.<br>Herald added a reviewer: tstellarAMD.<br>Herald added subscribers: jfb, mzolotukhin, joker.eph, arsenm.<br><br>If a local_unnamed_addr attribute is attached to a global, the address<br>is known to be insignificant within the module. It is distinct from the<br>existing unnamed_addr attribute in that it only describes a local property<br>of the module rather than a global property of the symbol.<br><br>This attribute is intended to be used by the code generator and LTO to allow<br>the linker to decide whether the global needs to be in the symbol table. It is<br>possible to exclude a global from the symbol table if three things are true:<br>- This attribute is present on every instance of the global (which means that<br> <span> </span>the normal rule that the global must have a unique address can be broken without<br> <span> </span>being observable by the program by performing comparisons against the global's<br> <span> </span>address)<br>- The global has linkonce_odr linkage (which means that each linkage unit must have<br> <span> </span>its own copy of the global if it requires one, and the copy in each linkage unit<br> <span> </span>must be the same)<br>- It is a constant or a function (which means that the program cannot observe that<br> <span> </span>the unique-address rule has been broken by writing to the global)<br><br>Although this attribute could in principle be computed from the module<br>contents, LTO clients (i.e. linkers) will normally need to be able to compute<br>this property as part of symbol resolution, and it would be inefficient to<br>materialize every module just to compute it.<br></blockquote><div><br></div></div></div><div>Cool, this last part is really key.</div><div><br></div><div><br></div><div>My real problem with adding this as a normal attribute is that I'm not sure what it really means. Is it just a "cache" of some local analysis? Do we expect things to invalidate it if they make the address significant within a module? Is this something that would be "blessed" by some frontends?</div><div><br></div><div>I feel like, from your description, this really is just intended to solve the problem of materializing all of the module. It would seem that for that purpose something more akin to the "summary" information used by ThinLTO would be a better tool than an attribute which has to have a semantic contract for the IR.</div><div><br></div><div>What do you think?</div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>To a certain extent this is a summary of the module contents, and in most cases I'd expect the property to simply summarize the module.</div><div><br></div><div>However, it is also a property that should be preserved if a pass introduces an address comparison. Modulo bugs, the new comparison should be "benign" -- if the original program could not observe the address, the optimized program shouldn't be able to observe it either.</div><div><br></div><div>One example of this would be a comparison of a vptr against a vtable or function address for speculative devirtualization, or in general any form of PGO that relies on global addresses. The introduction of such a comparison doesn't invalidate the unnamed_addr property (which we do currently apply to vtables), as the program would still have the same semantics if we, say, merged two identical vtables. The same applies to the local_unnamed_addr property.</div><div><br></div><div> Regarding frontends, yes, I'd expect that if a frontend knows that all address comparisons within a module are benign, it could apply this property.<br></div></div></div></div></blockquote><div><br></div></div></div><div>OK, all of this argues that we *can* define this as a semantic attribute, but doesn't really speak to why we *should*.</div></div></div></blockquote></div></div></div></div></blockquote><div><br></div><div><br></div></div></div><div style="word-wrap:break-word"><div><div>As Peter mentioned above, some transformations can introduce constructs that would prevent from inferring the attribute, which means that when writing out bitcode we won't be able to generate it.  Because of that, having it only in the bitcode (like the summary) makes it more "fragile" (round-tripping may be broken).</div><div><br></div><div>It seems to me that if we don't make it first class in the IR, we will still want to have an analysis (or metadata) populated from the summary data that can be used to preverse this "property".</div></div></div></blockquote><div><br></div><div>An analysis to allow easy access makes perfect sense to me, and even something more akin to metadata might make sense.</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I don't see the fundamental difference between a metadata and an attribute when you start to attach it some semantic, it looks like an implementation detail to me. Maybe the difference is that we should always be able to drop a metadata without correctness issue?</div></div></div></blockquote><div><br></div><div>That combined with the specific mandate to actively drop metadata when transforming code unless you know how to update it correctly.</div><div><br></div><div>However, the fact that we fail in practice to do that quite often speaks to why a constructively correct design would be better IMO.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div> But it seems to me that this would apply to multiple existing attributes as well.</div></div></div></blockquote><div><br></div><div>I agree. There are a number of attributes that would be better served by having improved ability to run interprocedural analyses and cache their results. But I'd like to not make the situation worse. As I've mentioned, I think we have become a bit too willing to introduce attributes to LLVM's IR. Their cost often ends up being surprisingly large, and I suspect we should be more reluctant to accept them (where we can).</div></div></div></div></blockquote><div><br></div></div></div><div>I agree (that we should be more reluctant).</div><span><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><br><blockquote type="cite"><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote"><div><br></div><div>I'll try to explain why an IR attribute seems strange to me: we have to remember for all time to update it.</div><div><br></div><div>I think that IR attributes which only *reflect* or "cache" the state of the program itself make every transformation which could possibly invalidate them fragile. We have to continually remember the set of attributes to go and invalidate. Attributes seem much more important when they *promise* some state that may not be (re-)computable, and thus it is *necessary* to have a fundamental semantic bit to indicate that the property must hold. Even better when the properties themselves are inherently defined in a way that isn't invalidated by transformations.</div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>Isn't it exactly the case here?</div><div>Transformations will not invalidate it "conceptually" (the attribute would always be valid and we don't need to care about invalidating it), but on the other side transformations can turn the code into a form where we can't deduce the attribute anymore (i.e. what you described IIUC as 'we "promise"  that may not be (re-)computable').</div></div></div></blockquote><div><br></div><div>This is not the impression I was left with -- I was left specifically with the impression that the usage of the attribute would require that the implementation match.</div><div><br></div><div>If that isn't correct, that would at least go some way to making me more comfortable with this as an attribute.</div></div></div></div></blockquote><div><br></div></span><div>That's not my understanding, Peter may be able to confirm?</div></div></div></blockquote><div><br></div><div>Yes, I think there might have been a misunderstanding here. The local_unnamed_addr attribute (and unnamed_addr) both reflect a property of the source code. The IR does not have to match that attribute, as transformations may introduce comparisons, which must be unobservable (per the general principle that passes cannot change observable semantics), and as such do not invalidate the attribute.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div>I'd expect any transformation that really invalidates this attribute to also invalidate unnamed_addr somehow. And while some transformations can prevents from computing it (by introducing a comparison on the address when messing with loops for instance), they don't really escape the address and I don't think any transform is invalidating unnamed_addr today.</div></div></div></blockquote><div> </div><div><div>Exactly, the only pass we have in the tree that "invalidates" unnamed_addr is the constant merge pass [1], which has legitimate reasons for doing so since it is merging source-level entities.</div></div><div><br></div></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div><div><br></div><div>[1] <a href="http://llvm-cs.pcc.me.uk/include/llvm/IR/GlobalValue.h/rsetUnnamedAddr">http://llvm-cs.pcc.me.uk/include/llvm/IR/GlobalValue.h/rsetUnnamedAddr</a></div></div></div>
</div></div>