<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Sean Silva" <chisophugis@gmail.com><br><b>To: </b>"Kevin B Smith" <kevin.b.smith@intel.com><br><b>Cc: </b>reviews+D12341+public+5f663c68720e9677@reviews.llvm.org, "Sanjay Patel" <spatel@rotateright.com>, "Chandler Carruth" <chandlerc@gmail.com>, "Krzysztof Parzyszek" <kparzysz@codeaurora.org>, "Hal Finkel" <hfinkel@anl.gov>, "Bob Wilson" <bob.wilson@apple.com>, kubastaszak@gmail.com, "llvm-commits" <llvm-commits@lists.llvm.org><br><b>Sent: </b>Saturday, August 29, 2015 12:11:18 AM<br><b>Subject: </b>Re: [PATCH] D12341: add llvm.unpredictable intrinsic and lower it to metadata<br><br><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Fri, Aug 28, 2015 at 8:16 AM, Smith, Kevin B <span dir="ltr"><<a href="mailto:kevin.b.smith@intel.com" target="_blank">kevin.b.smith@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">





<div lang="EN-US">
<div>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";">From:</span></b><span style="font-size: 10pt; font-family: "Tahoma","sans-serif";"> Sean Silva [mailto:<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>]
<br>
<b>Sent:</b> Thursday, August 27, 2015 5:39 PM<br>
<b>To:</b> <a href="mailto:reviews%2BD12341%2Bpublic%2B5f663c68720e9677@reviews.llvm.org" target="_blank">reviews+D12341+public+5f663c68720e9677@reviews.llvm.org</a>; Smith, Kevin B<br>
<b>Cc:</b> Sanjay Patel; Chandler Carruth; Krzysztof Parzyszek; Hal Finkel; Bob Wilson; <a href="mailto:kubastaszak@gmail.com" target="_blank">kubastaszak@gmail.com</a>; llvm-commits<span class=""><br>
<b>Subject:</b> Re: [PATCH] D12341: add llvm.unpredictable intrinsic and lower it to metadata<u></u><u></u></span></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Thu, Aug 27, 2015 at 3:13 PM, Kevin B. Smith via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p><span class="">
<p class="MsoNormal">kbsmith1 added a comment.<br>
<br>
No, I am not suggesting you have more history.  I am suggesting that you only have a single number that represents the percentage of time that the direction is mispredicted.  It would make a lot of sense for it to be a simple 0-100 value, and would represent
 the percentage of mispredictions. Anything else takes more space, and is much too closely tied to the branch predictor.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color: rgb(79, 129, 189);">I have seen 2 independent bug reports recently where the simple annotation to the compiler "assume that this is completely unpredictable" would have been the solution. Some pieces of code very closely approximate
 this, especially in decompression algorithms where by definition if the encoder is doing its job then the pattern cannot be guessed. Other data-driven branches can approximate this behavior as well.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color: rgb(79, 129, 189);"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color: rgb(79, 129, 189);">This is more a declaration about the actual pattern of the branch. A number indicating the percentage of mispredictions (or any empirically collected number) is not a generalization of this annotation.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color: rgb(79, 129, 189);"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color: rgb(79, 129, 189);">-- Sean Silva<u></u><u></u></span></p>
</div>
</span><div>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">Sean – Yes, I agree this is about an inherent property of the branch, or condition. But percentage of mispredictions could easily be used<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">to convey that information.  Simply set the value to 100 to say that 100% of the time the branch/condition is mispredicted, and consider that<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">the declaration about the actual pattern, rather than an actual number.</span></p></div></div></div></div></div></div></blockquote><div><br></div><div id="DWT2933">I think this is a perfect example of why using such a percentage needs more thought (especially which kinds of optimizations we would hope to do based on the number).</div></div></div></div></blockquote><br>I agree that we should not prematurely generalize. As I recall, I had asked whether it would make sense to use the same setup for this as we use for the branch-probability metadata. It seems the answer is a resounding no, and we understand why. I think the answer to your question is actually straightforward: A target hook would need to interpret that percentage and make some determination regarding whether the branch was unpredictable enough to treat in the non-default way. That having been said, I agree we should not add facilities with no users, and we can decide on the exact format once we have a user (profiling capability, etc.) that can provide such measurements.<br><br> -Hal<br><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> Think for a second about what it means for a branch to be 100% mispredicted. If I give you a 10 question T/F test with questions that you have no clue about, is it harder to get 10/10 or 0/10? (trick question).</div><div><br></div><div>Sanjay's patch is motivated by a specific use case (that has arisen in practice multiple times for us) where the user would like to inform the compiler that the branch should not be expected to be predictable in any way.</div><div><br></div><div>-- Sean Silva</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div lang="EN-US"><div><div><div><div><div><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">To some extent this mimics __builtin_expect, which allows a specification of the probability of a condition having a certain value, but where in actual usage,
 the user’s usage is likely to be always 0 or always 100 for hinting purposes.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">This allows a single type of annotation to be used for both the user specified property, and also for HW feedback.<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="HOEnZb"><font color="#888888">
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);">Kevin Smith<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Arial","sans-serif"; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
</font></span></div><span class="">
<blockquote style="border-width: medium medium medium 1pt; border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(204, 204, 204); padding: 0in 0in 0in 6pt; margin-left: 4.8pt; margin-right: 0in;">
<p class="MsoNormal"><br>
ABAB can be perfectly predicted often, AABB can be perfectly predicted often. The number of transitions from true to false or vice-versa has a poor<br>
correlation to branch predictability, just as the branch probability has a poor correlation to branch predictability.<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<a href="http://reviews.llvm.org/D12341" target="_blank">http://reviews.llvm.org/D12341</a><br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><u></u><u></u></p>
</div>
</div>
</blockquote>
</span></div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>

</blockquote></div><br></div></div>
</blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>