<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>"Daniel Berlin via llvm-dev" <llvm-dev@lists.llvm.org><br><b>To: </b>"Peter Lawrence" <c_plawre@qca.qualcomm.com><br><b>Cc: </b>llvm-dev@lists.llvm.org<br><b>Sent: </b>Tuesday, June 14, 2016 12:45:50 PM<br><b>Subject: </b>Re: [llvm-dev] Early CSE clobbering llvm.assume<br><br><div dir="ltr"><br><div class="gmail_extra"><br><div id="DWT2444" class="gmail_quote">On Tue, Jun 14, 2016 at 10:36 AM, Lawrence, Peter <span dir="ltr"><<a href="mailto:c_plawre@qca.qualcomm.com" target="_blank">c_plawre@qca.qualcomm.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: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Daniel,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"> What am I missing in the following chain of logic:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">As far as constant-prop, value-prop, range-prop, and general property-propagation,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">1. the compiler/optimizer *<b>has</b>* to get it right for if-then-else and while-do or else we should all start over
</span><span style="font-size: 11pt; font-family: Wingdings; color: rgb(31, 73, 125);">J</span></p></div></div></blockquote><div><br></div><div>Only certain parts of the compiler know how to do this.</div><div>This is precisely one of the reasons i'm proposing we've gotten it wrong.</div><div> <br></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><p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">2. “assert” takes advantage of this by being translated into if-then logic early on in the compilation<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">3. “assume” should also take advantage of this the same way. (generate a call to “pseudoabort” which<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">At some late stage gets deleted)</span></p></div></div></blockquote><div><br></div><div>This would fix precisely nothing, because of the above.</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><p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><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<u></u><u></u></span></p>
<p class="MsoNormal"><span id="DWT2443" 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></blockquote></div></div></div></blockquote>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.<br><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. <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"><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: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"></span></p></div></div></blockquote><br><div><br></div><div>Asserts occur much more often than assumes, it may or may not be sensible to handle them the same way.</div><div id="DWT1315">I would argue it is sensible, but it's also reasonable to argue it is not.</div></div></div></div></blockquote>We need to be careful what we mean by "in the same way". For clarify, I'll note that:<br><br> 1. assert is defined to be a macro that does not result in semantically-analyzable code when NDEBUG is defined. We cannot elide this, it how the feature is defined. The body of the assert might not even be parsable code when NDEBUG is defined. It might, for example, refer to variables that are only declared when NDEBUG is not defined.<br><br> 2. Even saying that we'd get around this by ignoring parsing errors within the assert when NDEBUG is defined, but otherwise assuming the result is not desirable. There are large bodies of code which do this;<br><br> assert(i > 5);<br> if (i <= 5) throw a_strange_error();<br><br>so that, in production builds, the program does not crash, but instead unwinds. There are all sorts of reasons we can use to argue this is a bad coding practice, and I personally agree, but that does not change the fact that braking this idiom is not something we should do.<br><br>The contracts features being discussed for future versions of the C++ standard should be better in this regard.<br><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.<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 dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>I would also argue our current way of propagating information for if-then conditions is in fact, quite crappy. Only a small number of passes know how to do it, and they do it either by ad-hoc analysis (GVN) or very expensive methods (LVI).<br></div><div><br></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><p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">And any argument you can make about needing to handle “assume” conditions in some special way can be<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Turned around and applied to “if-then” conditions, but again no one is arguing that we need to re-design “if-then”<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri",sans-serif; color: rgb(31, 73, 125);">Information propagation.</span></p></div></div></blockquote><div>I would argue we do, in fact need to do that.</div><div><br></div><div>That said, it is a larger longer term change.</div><div><br></div><div>Fixing assume is a good start on that, and by fixing assume, we can prove out whether a new model will work well and expand it.</div><div>If we start by trying to fix the general propagation problem, that's a huge job to start, and if we get it wrong, a lot larger to fix.</div><div>Better to start small and go from there.</div><div><br></div></div></div></div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></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>