On Wed, May 15, 2013 at 9:42 PM, Bob Wilson <span dir="ltr"><<a href="mailto:bob.wilson@apple.com" target="_blank">bob.wilson@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><div class="h5"><br><div><div>On May 15, 2013, at 9:10 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><br><blockquote type="cite">
<div style="letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">On Wed, May 15, 2013 at 8:57 PM, Chris Lattner<span> </span><span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span><span> </span>wrote:<br>
<div class="gmail_quote"><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><br><div><div>On May 15, 2013, at 8:50 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div><blockquote type="cite"><div class="gmail_quote"><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 class="gmail_quote"><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 class="gmail_quote"><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 dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><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>1) The 'nobuiltin' attribute doesn't actually prevent the optimization (see recent patch on llvmcommits)</div>
<div>2) We can't block the optimization if the call happens through a function pointer, unless we also annotate all calls through function pointers as 'nobuiltin'</div><div><br></div><div>How feasible would it be to make the 'builtin-ness' of _Znwm etc be opt-in rather than opt-out? Is there some other option we could pursue?</div>
</blockquote></div></div></div></blockquote></div></blockquote><div><br></div><div>Wow, this was spectacularly unclear, sorry about that. To avoid confusion, I'm suggesting that we add a 'builtin' attribute, and do not treat a call to _Znwm as a builtin call unless it has the attribute.</div>
<div> </div></div></blockquote><br></div><div>It's not clear to me that "builtin" is the right way to model this, but it definitely sounds like this should be an attribute on a call site (as opposed to on the function itself). What specific kinds of optimizations are we interested in doing to _Znwm calls?</div>
</div></blockquote><div><br></div><div>Initially, I'm just concerned about keeping the optimizations we already perform, such as globalopt lowering a new/delete pair into a global, while disabling the non-conforming variations of those optimizations. But we're also permitted to merge multiple allocations into one if they have sufficiently similar lifetimes.</div>
</div></blockquote></div><br></div><div>So your proposal is for Clang to slap the attribute on explicit calls to ::operator new, but any other use of the symbol (e.g. from C code or something else weird) can be optimized?</div>
</div></blockquote><div><br></div><div>No, because Clang cannot statically detect which indirect calls might call ::operator new. Instead, my proposal is to add a 'builtin' attribute to LLVM, and then for clang to add that attribute to the calls which can be optimized.</div>
<div><br></div><div>If you think the C code / weird cases are important, a more nuanced option springs to mind:</div><div><br></div><div>* Allow the 'nobuiltin' attribute on function declarations</div><div>* Add a 'builtin' attribute, permitted only on direct calls to 'nobuiltin' functions, which overrides the 'nobuiltin' attribute on the function</div>
<div><br></div><div>Would that be preferable?</div></div></div></blockquote><br></div></div></div><div>Just curious: will this fix the issue that we discussed last month in the context of r179071 regarding the need to compile with -fno-builtin if you have code with custom new operators? (<a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/170888.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20130408/170888.html</a>)</div>
</div></blockquote></div><br><div>It would fix the problem if that operator new is being called explicitly, but not if it's being called via a new-expression. The recent change to the C++ standard doesn't address whether we're required to respect the inital value of the memory produced by a user replacement operator new, but that may well be covered by the normal C++ lifetime rules.</div>