<div dir="ltr">LLVM has an argument promotion pass that does this exact transform, but it only works on internal functions.<div><br></div><div>Unfortunately, functions with vague linkage all need to have the same prototype across all TUs, so we can't do this transform to a function without internalizing it. We should only internalize small functions, which are typically good candidates for inlining, which makes the exercise kind of pointless.</div><div><br></div><div>In theory, C++ programmers could create and use a type trait that indicates that pass-by-value is more efficient for a type than pass-by-const-reference. However, that would probably make really complicated code, so I wouldn't suggest it.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 11, 2017 at 1:49 AM, Francois Fayard via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Because of the emphasis on generic programming, the C++ standard library has many weird signatures such as:<br>
<br>
const int& std::min(const int& a, const int& b) (1)<br>
<br>
where one would expect a:<br>
<br>
int std::min(int a, int b) (2)<br>
<br>
I thought that this would not matter from a performance point of view as those functions are inlined anyway. And it turns out that when you replace a signature such as (2) into (1) where the function is inlined, the assembly does not change at the call site: both are inlined properly.<br>
<br>
But I came to realize that some side effects are cascaded to other parts of the code, and codes that use (1) end up being slower than code using (2), wether the compiler is clang, gcc or intel compiler (even though the loss of performance differs from compiler to compiler).<br>
<br>
Is there any fundamental reason for this? Would you recommend avoiding signatures such as (1) which end up being used a lot when min is template-defined?<br>
<br>
Best regards,<br>
Francois<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>