On Wed, May 15, 2013 at 8:41 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.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 dir="ltr"><div><div class="h5">On Wed, May 15, 2013 at 9:28 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br></div></div><div class="gmail_extra">
<div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>On Wed, May 15, 2013 at 7:49 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>On Wed, May 15, 2013 at 8:31 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br></div></div>
<div class="gmail_extra">
<div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<div><br></div><div>LLVM classifies _Znwm as a builtin by default. After some discussion, the C++ core working group have decreed that that is not correct: calls to "operator new" *can* be optimized, but only if they come from new-expressions, and not if they come from explicit calls to ::operator new. We cannot work around this in the frontend by marking the call as 'nobuiltin' for two reasons:</div>
<div><br></div><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><br></div></div></div><div>I think we should just fix this when we build the system which allows optimizing new expressions. Specifically, when we introduce a way to mark new expressions for LLVM to optimize, that's the time to make the builtin-ness of _Znwm opt-in instead of opt-out.</div>
</div></div></div></blockquote><div><br></div></div><div>This 'builtin' attribute would *be* building the system which allows optimizing new-expressions.</div></div></blockquote><div><br></div></div></div><div>You hadn't mentioned a 'builtin' attribute! =D Now I understand. Yes, I definitely think this is the right fundamental design.</div>
<div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div>Suggested transition plan:<br></div><div>1) add 'builtin' attribute</div>
<div>2) make Clang use it</div><div>3) make _Znwm and friends not be implicitly builtin </div></div>
</blockquote></div></div><br></div><div class="gmail_extra">This sequence is all I was looking for of course. Thanks for clarifying.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I do wonder whether 'builtin' is the best tool (I think it is, but its something that I'd love to hear more opinions about from others...</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">And if we want to keep 'nobuiltin', or just auto-upgrade to invert things?</div></div></blockquote><div><br></div><div>I think 'nobuiltin' makes sense for the vast majority of cases. operator new/delete are special only because C++ allows them to be replaced by functions which are not semantically identical to the default forms. Adding 'builtin' to all direct calls to these functions when upgrading makes sense to me.</div>
</div>