<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>"Peter Lawrence" <c_plawre@qca.qualcomm.com><br><b>To: </b>"Daniel Berlin" <dberlin@dberlin.org><br><b>Cc: </b>"Hal Finkel" <hfinkel@anl.gov>, "llvm-dev" <llvm-dev@lists.llvm.org><br><b>Sent: </b>Thursday, June 16, 2016 6:02:22 PM<br><b>Subject: </b>assumptions about assume, was: RE: [llvm-dev] Early CSE clobbering llvm.assume<br><br>


<style><!--

@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}

p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>

<div class="WordSection1">
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Daniel,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">              Here’s a relatively simple question that should not start a runaway thread (!?)</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Is “assume” something the user supplies information with, like “assert”,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Or is “assume” something the compiler inserts as a result of analysis,</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">I originally thought it was the former, but these various emails have convinced me</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">That it is instead the later (except for the comment about “contracts”, which I hope</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">We can leave out of the discussion for now).</span></p>
<p class="MsoNormal"><span id="DWT18398" style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p></div></blockquote>It is generally the former, or it could be the frontend as a way to capture some aspect of the language semantics useful for optimization. Clang, for example, supports __builtin_assume (and __builtin_assume_aligned) which are implemented in terms of LLVM's assume facility. Some of the alignment-related attributes are also lowered this way.<br><br> -Hal<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 class="WordSection1"><p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">--Peter Lawrence.</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">(I also ask that no one replies to this thread saying that the user is not “supplying information”</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">With assert, that is a separate thread !!!)</span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal"><b><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">From:</span></b><span style="font-size: 11pt; font-family: "Calibri",sans-serif;"> Daniel Berlin [mailto:dberlin@dberlin.org]
<br>
<b>Sent:</b> Tuesday, June 14, 2016 9:41 PM<br>
<b>To:</b> Lawrence, Peter <c_plawre@qca.qualcomm.com><br>
<b>Cc:</b> Hal Finkel <hfinkel@anl.gov>; llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Early CSE clobbering llvm.assume</span></p>
<p class="MsoNormal"> </p>
<div>
<div>
<p class="MsoNormal">I suspect this thread has become deep enough that it is becoming somewhat unproductive and if we really want to carry it on, it may be more useful to do so at a social or something.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">I suspect this mainly because you can't tell who i'm quoting, and folks are replying to things other people have not quite said, due to the quoting :)</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">There seem to be other confusions, such as use of common llvm terminology that is not always common in other parts of the world of compilers (unreachable, undef, etc).</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<div>
<p class="MsoNormal">On Tue, Jun 14, 2016 at 7:04 PM, Lawrence, Peter <<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.com</a>> wrote:</p>
<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: 5pt 0in 5pt 4.8pt;">
<div>
<div>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Daniel,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">              This first part is to whoever you are quoting, I can’t tell from the email,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">The more information made available to the optimizers the better the optimizations,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Asserts provide more information,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">You *<b>should</b>* expect better code with asserts enabled.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">And this is *<b>not</b>* a bad thing !!!</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">And IMHO there is no winning argument that says we should not use this information.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">In other words saying “asserts aren’t for optimization” isn’t a winning argument,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Its information and it isn’t useful to throw that information away.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">It’s not very far removed from saying “if, while, and for conditions” aren’t for optimization.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">This second part is for your response,</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Hmmm, I don’t get how you go from “assert having a call to abort()” to a bunch of talk</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">About “branch around unreachable” ?  the condition isn’t unreachable, the abort isn’t</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Unreachable, what’s unreachable ???</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">--Peter.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> </span></p>
<p class="MsoNormal" style=""><b><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">From:</span></b><span style="font-size: 11pt; font-family: "Calibri",sans-serif;"> Daniel Berlin [mailto:</span><a href="mailto:dberlin@dberlin.org" target="_blank"><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">dberlin@dberlin.org</span></a><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">]
<br>
<b>Sent:</b> Tuesday, June 14, 2016 11:23 AM<br>
<b>To:</b> Hal Finkel <</span><a href="mailto:hfinkel@anl.gov" target="_blank"><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">hfinkel@anl.gov</span></a><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">><br>
<b>Cc:</b> Lawrence, Peter <</span><a href="mailto:c_plawre@qca.qualcomm.com" target="_blank"><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">c_plawre@qca.qualcomm.com</span></a><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">>;
 llvm-dev <</span><a href="mailto:llvm-dev@lists.llvm.org" target="_blank"><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">llvm-dev@lists.llvm.org</span></a><span style="font-size: 11pt; font-family: "Calibri",sans-serif;">><br>
<b>Subject:</b> Re: [llvm-dev] Early CSE clobbering llvm.assume</span></p>
<p class="MsoNormal" style=""> </p>
<div>
<div>
<div>
<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: 5pt 0in 5pt 4.8pt;">
<div>
<blockquote style="border-width: medium medium medium 1.5pt; border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(16, 16, 255); padding: 0in 0in 0in 4pt; margin-left: 3.75pt; margin-top: 5pt; margin-bottom: 5pt;">
<div>
<div>
<div>
<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: 5pt 0in 5pt 4.8pt;">
<div>
<p class="MsoNormal" style=""><span style="font-family: "Helvetica",sans-serif; color: black;"> </span></p>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Sanjoy’s argument is faulty, if it were true we would also find our handling of “assert” to be unacceptable</span></p>
<div>
<div>
<p class="MsoNormal" style=""><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">but this is not the case, no one is arguing that we need to re-design “assert”</span></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Arial",sans-serif; color: black;">Sure, but no one should make this argument anyway: assert is not for optimization. In fact, we don't really
 want it to be used for optimization, because if we do, then we might end up in a situation where the -DNDEBUG build generates worse code than the build with asserts enabled.</span></p>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<div>
<p class="MsoNormal" style="">:)</p>
<p class="MsoNormal" style=""> </p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Arial",sans-serif; color: black;"><br>
Also, I'll note that the reason that assume is an intrinsic, instead of a branch around unreachable, is that we aggressively remove branches around unreachable as part of our canonicalization process. We do this in order to simplify code, and this is important
 in order to remove abstraction penalties. Note that unreachables are also generated from undefined behavior, and one of the ways we use undefined behavior is to assume it is unreachable, enabling us to eliminate what should be dead code. This is an important
 technique for limiting abstraction penalties from, for example, heavily templated C++ code.<br>
<br>
Thus, somewhat unfortunately, Sanjoy's argument is not faulty. </span></p>
<p class="MsoNormal" style=""><span style="font-family: "Helvetica",sans-serif; color: black;"> </span></p>
<p class="MsoNormal" style=""><span style="font-family: "Helvetica",sans-serif; color: black;"> </span></p>
<p class="MsoNormal" style=""><span style="font-family: "Helvetica",sans-serif; color: black;">Asserts occur much more often than assumes, it may or may not be sensible to handle them the same way.</span></p>
<p class="MsoNormal" style=""><span style="font-family: "Helvetica",sans-serif; color: black;">I would argue it is sensible, but it's also reasonable to argue it is not.</span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Arial",sans-serif; color: black;">We need to be careful what we mean by "in the same way".</span></p>
<p class="MsoNormal" style=""> </p>
<p class="MsoNormal" style="">Yes, i simply meant "extract information from the control flow structure and comparisons they generate when they are enabled".</p>
<p class="MsoNormal" style=""> </p>
<p class="MsoNormal" style="">You are correct with all of your observations :)</p>
<p class="MsoNormal" style="margin-bottom: 12pt;"><span style="font-size: 10pt; font-family: "Arial",sans-serif; color: black;"><br>
We can certainly improve the representations of assumes, perhaps as Danny has suggested by converting their control dependencies into extended SSA token vales, and better capture knowledge from conditional branches, but the tradeoffs here are not trivial.</span></p>
<p class="MsoNormal" style=""> </p>
<p class="MsoNormal" style="">100% agreed, this is something that requires some exploration and messing around, and then a design document going through the tradeoffs of various approaches with real data.</p>
<p class="MsoNormal" style=""> </p>
<p class="MsoNormal" style=""> </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"> </p>
</div>
</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>