<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 22, 2016, at 10:27 AM, Sanjay Patel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><br class="Apple-interchange-newline"><br class=""><div class="gmail_quote">On Fri, Apr 22, 2016 at 10:39 AM, Philip Reames<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:listmail@philipreames.com" target="_blank" class="">listmail@philipreames.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div text="#000000" bgcolor="#FFFFFF" class=""><span class=""><br class=""><br class=""><div class="">On 04/22/2016 09:20 AM, Sanjay Patel via llvm-dev wrote:<br class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><div class="">I've proposed removing the llvm.expect intrinsic:<br class=""><a href="http://reviews.llvm.org/D19300" target="_blank" class="">http://reviews.llvm.org/D19300</a><br class=""><br class=""></div>The motivation for this change is in:<br class=""><a href="http://reviews.llvm.org/D19299" target="_blank" class="">http://reviews.llvm.org/D19299</a><br class=""><br class="">For reference:<br class="">1. We created an intrinsic that's only reason for existing is to improve perf, but the intrinsic can harm optimization by interfering with transforms in other passes.<br class=""></div></div></blockquote></span>I don't follow this at all. Given expects are eagerly lowered to metadata, where's the interaction? In particular, the expect lowering overrules any metadata on the associated branch/switch. This is exactly what you'd expect for a user annotation interacting with PGO data.</div></blockquote><div class=""><br class=""></div><div class="">I agree that a user annotation should override PGO data.</div></div></div></div></div></blockquote><div><br class=""></div><div>PGO is also a user input: the user is basically saying "I want the code to be optimized for *this* use case".</div><div><div>So interestingly I would have thought the opposite: PGO overrides the source code annotation.</div></div><div>Here are a couple of reasons why:</div><div> - libraries can be used by different client and what is common in one case might not for another.</div><div> - code evolves, and user can fail to revisit assumption about the common case</div><div> - the user can be wrong, PGO should not (?).</div><div><br class=""></div><div>-- </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> This is why I initially proposed that builtin_expect() would extend on '[un]predictable' metadata rather than 'prof' metadata in D19299.<span class="Apple-converted-space"> </span><br class=""><br class="">But I think that's a separate discussion now; we use 'prof' metadata for this purpose today, and I'm not trying to change that in these patches. If the user-specified representation of builtin_expect() is overwritten by PGO data, I think that's a bug independent of the current proposal/patches.<br class=""></div><div class=""><br class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div text="#000000" bgcolor="#FFFFFF" class=""><span class=""><br class=""><blockquote type="cite" class=""><br class=""><div dir="ltr" class=""><div class="">2. To solve that, we created a pass to always transform the intrinsic into metadata at a very early stage in LLVM. But now every program is paying a compile-time tax (running the LowerExpectIntrinsic pass) for a feature that is rarely used.<br class=""></div></div></blockquote></span>Er, what cost? Given this is a single linear pass over the IR - and could actually be made essentially free by checking to see if the module has any uses of expect - I'm suspicious of this compile time argument. Have you actually seen this in profiles? <span class="Apple-converted-space"> </span><br class=""></div></blockquote><div class=""><br class=""></div><div class="">No - I expect the actual overhead is in the noise. The real objection to the LowerExpectIntrinsic pass is that it is completely unnecessary. This was raised in the original review. We shouldn't have two mechanisms to represent exactly the same thing. This is also why my initial implementation for builtin_unpredictable() was rejected:<br class=""><a href="http://reviews.llvm.org/D12341" class="">http://reviews.llvm.org/D12341</a><br class=""><br class=""></div><div class="">I assumed there was some good reason for LowerExpectIntrinsic to exist, so I copied that design. As noted in that review, my assumption was wrong. And it was suggested then that we should remove LowerExpectIntrinsic but nobody had gotten around to it. With these patches, I'd like to finally fix this.<br class=""></div><div class=""><br class=""><br class=""><br class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div text="#000000" bgcolor="#FFFFFF" class=""><span class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><br class="">A possible front-end replacement transformation for a source-level "builtin_expect()" is in D19299: I think a front-end can always directly create metadata for this kind of programmer hint rather than using an intermediate representation (the intrinsic). Likewise, if there's some out-of-tree IR pass that is creating an llvm.expect, it should be able to create branch weight metadata directly instead.<br class=""></div></div></blockquote></span>This seems like a reasonable proposal. The expect intrinsic does give us a mechanism to express value profiling predictions, but we don't appear to actually use that today. My bias would be to leave it in place, but I'm not going to object strongly if the consensus goes the other way. <span class="Apple-converted-space"> </span><br class=""><blockquote type="cite" class=""><span class=""><div dir="ltr" class=""><div class=""><br class="">Please let me know if you see any problems with this proposal or the patches.<br class=""><br class=""></div><div class="">For reference, here's the original post-commit review thread for llvm.expect:<br class=""><a href="https://marc.info/?l=llvm-commits&m=130997676129580&w=4" rel="noreferrer" target="_blank" class="">https://marc.info/?l=llvm-commits&m=130997676129580&w=4</a><br class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><fieldset class=""></fieldset><br class=""></span><pre class="">_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre></blockquote><br class=""></div></blockquote></div><br class=""></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">LLVM Developers mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-dev@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">llvm-dev@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div></blockquote></div><br class=""></body></html>