<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 14 March 2014 22:02, John Colvin <span dir="ltr"><<a href="mailto:john.loughran.colvin@gmail.com" target="_blank">john.loughran.colvin@gmail.com</a>></span> wrote:<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">

<br>
Thanks for the explanations.<br>
<br>
Another use case is to aid propogation of compile-time information for optimisation.<br>
A function might look like a poor candidate for inlining for other reasons, but if there's a statically known (to the caller) integer parameter coming in that will be used to decide a loop length, inlining allows that info to be propogated to the callee. Static loop lengths => well optimised loops, with opportunities for optimal unrolling. Even with quite a large function this can be a good choice to inline.<br>
</blockquote><div><br></div><div>Yup, this is a classic example. Extremely relevant.</div><div>And it's precisely the sort of thing that an inline heuristic is likely to fail at.</div><div><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">

I don't know how good compilers are at taking this sort of thing into account already.<br>
</blockquote></div><br></div><div class="gmail_extra">I don't know if they try or not, but I can say from experience that results are generally unreliable.</div><div class="gmail_extra">I would never depend on the inliner to get this right.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">On 14 March 2014 22:08, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com" target="_blank">bearophileHUGS@lycos.com</a>></span> wrote:<br>
<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">John Colvin:<div class=""><br><br><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">
...<br></blockquote><br></div>If the function is private in a module, and it's called only from one point (or otherwise the loop count is the same in different calls), I think this optimization can be performed even if the function is not inlined.<br>
</blockquote><div><br></div><div>This is probably true, but I would never rely on it.</div><div>You have some carefully tuned code that works well, and then one day, some random unrelated thing tweaks a balance, and your previously good code is suddenly slow for unknown reasons.</div>
<div><br></div><div>The point is, there are times when you know your code should be inlined; ie, it's not an 'optimisation', it's an expectation/requirement. A programmer needs to be able to express this.</div>
</div></div>