<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 22, 2016 at 11:41 AM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">PGO is also a user input: the user is basically saying "I want the code to be optimized for *this* use case".</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>So interestingly I would have thought the opposite: PGO overrides the source code annotation.</div></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Here are a couple of reasons why:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> - libraries can be used by different client and what is common in one case might not for another.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> - code evolves, and user can fail to revisit assumption about the common case</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> - the user can be wrong, PGO should not (?).</div></div></blockquote><div><br></div></span><div>For this last point, whatever information prevails in the end, it may be valuable to report to the user some optimization hints about the mismatch between the PGO measurement and the annotation.</div><span></span><span class=""></span></div><br></div></blockquote><div><br></div><div>I like that idea. My feeling is that builtin_expect() should be treated like a super-power. If it's wrong, it's the programmer's fault. But I understand your point that PGO is another user input.<br><br></div><div>Note that the GCC docs (because there's no corresponding clang doc for this afaict) do warn:<br>"You may use <code>__builtin_expect</code> to provide the compiler with
branch prediction information.  In general, you should prefer to
use actual profile feedback for this (<samp><span class="">-fprofile-arcs</span></samp>), as
programmers are notoriously bad at predicting how their programs
actually perform."<br></div></div><br></div></div>