<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Mar 7, 2017 at 3:10 AM Roger Ferrer Ibanez <<a href="mailto:Roger.FerrerIbanez@arm.com">Roger.FerrerIbanez@arm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple" class="gmail_msg">
<div class="m_-255068685208760049WordSection1 gmail_msg">
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">Thanks David for your answer, would it make sense to do this at CodeGen under –O?</span></p></div></div></blockquote><div><br>I doubt it - the Clang code isn't really designed to be an efficient optimizer. If this is a missed optimization, it'd likely be best to look at why the LLVM optimization pipeline is missing the opportunity.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-GB" link="blue" vlink="purple" class="gmail_msg"><div class="m_-255068685208760049WordSection1 gmail_msg"><p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">Something like, in CodegenFunction::EmitCallExpr check that we’re calling a constexpr function, then attempt to evaluate it, and then forward down a llvm::Constant*
 until CodeGenFunction::EmitCall (the one in CGCall.cpp). Then there if given a non-null llvm::Constant*, use that to create and return the RValue. This seems unnecessarily complicated but should emit everything else required at that point except the function
 call itself.<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">Kind regards,<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg">Roger<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt" class="gmail_msg">
<div class="gmail_msg">
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm" class="gmail_msg">
<p class="MsoNormal gmail_msg"><b class="gmail_msg"><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="gmail_msg">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="gmail_msg"> David Blaikie [mailto:<a href="mailto:dblaikie@gmail.com" class="gmail_msg" target="_blank">dblaikie@gmail.com</a>]
<br class="gmail_msg">
<b class="gmail_msg">Sent:</b> 22 February 2017 16:16<br class="gmail_msg">
<b class="gmail_msg">To:</b> Roger Ferrer Ibanez; Clang Dev; Richard Smith<br class="gmail_msg">
<b class="gmail_msg">Subject:</b> Re: [cfe-dev] Folding constexpr function calls with constant arguments in non constant expression contexts<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
</div>
</div></div></div></div><div lang="EN-GB" link="blue" vlink="purple" class="gmail_msg"><div class="m_-255068685208760049WordSection1 gmail_msg"><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt" class="gmail_msg">
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<div class="gmail_msg">
<p class="MsoNormal gmail_msg" style="margin-bottom:12.0pt">I'm going to guess it's mostly (3). Checking and trying to constant evaluate every subexpression would be expensive - the systems to do so in Clang have to do a lot of work to properly report diagnostics, to
 act on the full AST form, etc. It's easier to leave it to the LLVM optimization passes to do the work, when possible.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<div class="gmail_msg">
<div class="gmail_msg">
<p class="MsoNormal gmail_msg">On Wed, Feb 22, 2017 at 1:58 AM Roger Ferrer Ibanez via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm" class="gmail_msg">
<p class="MsoNormal gmail_msg">Hi all,<br class="gmail_msg">
<br class="gmail_msg">
maybe this is just a silly question. But I wondered why clang is not attempting to fold calls to constexpr functions in non-constant expression contexts.<br class="gmail_msg">
<br class="gmail_msg">
Example:  <a href="https://godbolt.org/g/KBaMjp" class="gmail_msg" target="_blank">https://godbolt.org/g/KBaMjp</a> just compare "one" vs "two" in the IR<br class="gmail_msg">
<br class="gmail_msg">
I understand that clang does not have to do this and I'm not saying it should.<br class="gmail_msg">
<br class="gmail_msg">
But I'd like to know what is the rationale here.<br class="gmail_msg">
- Is it a C++ Standard issue?, i.e. doing that would trigger some side-effects that would be non-compliant.<br class="gmail_msg">
- Is it a "separation of concerns" issue?, i.e. let LLVM optimize these cases and improve if it can't.<br class="gmail_msg">
- Is it a speed issue?, i.e. even if the original AST is preserved for fidelity, computing an associated constant value to it takes time which is precious for some clients.<br class="gmail_msg">
<br class="gmail_msg">
Or maybe it is something else that didn't occur to me.<br class="gmail_msg">
<br class="gmail_msg">
Thank you,<br class="gmail_msg">
Roger<br class="gmail_msg">
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
</blockquote>
</div>
</div>
</div></div></div></blockquote></div></div>