<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font face="HelveticaNeue" class=""><span class="" style="background-color: rgb(255, 255, 255);">John,</span><br class=""></font><div class=""><div class=""><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Sanjoy,</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Nuno,</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">David,</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">         Thanks for the tip, below are the relevant posts from the archives</font></span><span style="font-family: HelveticaNeue;" class="">.</span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">I am suggesting something similar to Dan's third option below (Tue Nov 29 2011  </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">"the nsw story”, Dan Gohman), when hoisting an instruction with ‘nsw’ it looses</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">the ‘nsw’ attribute, but without saying “add-nsw is a fully side-effecting</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">instruction”.</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">This option was back then seen by Dan as too much effort, but the current</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">proposal requires at least the same amount of effort. To be specific the</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">current proposal requires adding “freeze” instead of removing “nsw”. It is</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">pretty much the same amount of editing work on the compiler sources either</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">way as far as add/sub/mul/shl are concerned.</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">The difference is that removing “nsw” from an operation is simpler and cleaner</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">than adding “freeze” to it, and in software engineering we are always striving </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">for the simplest and cleanest solution.</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">IIUC option three does not inhibit Dan's original goal of promoting 32-bit </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">induction variables to 64-bit on an LP64 target. And I don’t agree with Dan's </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">description of this being “suboptimal” for any other reason, the lost </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">information does not seem to be useable AFAICT, but if you disagree then simply </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">insert an “llvm.assume" in the spot where the operation is being hoisted from.</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">So I propose that we revisit this option.  It was never fully explored in Dan’s</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">original email, nor in any subsequent emails, and now especially it seems to </font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">deserve it.</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Thoughts ?</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Comments ?</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Questions ?</font></span></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 13px;"><font face="HelveticaNeue" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div class="" style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><font face="HelveticaNeue" class="">Peter Lawrence.</font></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">2011: =========================================================================</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">------------------------------------------------------------------------</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">Mon Dec 12 2011  "nsw is still logically inconsistent" (Dan Gohman)</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">   </span>Dan provides this example</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">       </span>i32 a,b; i64 c,d,e,f;</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">   </span></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>if (cond) {                // assume cond prevents signed wrap</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">  </span>  c = sext64( a +nsw b )   // upper 33-bits all 1's or all 0's</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>  d = (c >> 31) + 1        // 0 or 1 result</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">      </span>  e = d <u 2               // 1 result</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">       </span>  f = 1 / e                // no possible divide-by-zero</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">   </span>}</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">       </span>the problem is when the compiler tries to speculatively hoist everything</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>out of the if-cond. now when (a +nsw b) does overflow wrap, the</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;"> </span>promotion of a and b to i64 means sext64(a) + sext64(b) can evaluate</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">    </span>to something whose upper 33-bits aren't all 1's or all 0's and we can</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">   </span>end up with divide-by-zero.</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">     </span></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>(remember that nsw was introduced to allow promotion to i64 to</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">  </span>allow eliminating sext64 on LP64 targets, they haven't been</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">     </span>eliminated in this example because the actual goal is just to</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">   </span>hoist the sext64 out of a loop which isn't shown for simplicity)</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>===> the thread is left unresolved, whatever llvm is actually</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>     doing to resolve the problem isn't documented here <===</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">------------------------------------------------------------------------</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">Thu Dec  1 2011  "the nsw story" --- continued</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">      </span>Dan shows this argument against option 1 (“undef" as alt to "poison")</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">  </span>but its still not clear how "poison" solves the problem</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">int a = INT_MAX, b = 1;</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">long c = (long)(a + b);</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">What is the value of c, on an LP64 target?</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">By standard C rules, the add overflow invokes immediate undefined behavior of course.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">If a and b are promoted to 64-bit, c is 0x0000000080000000.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">In a world where signed add overflow returns undef, c could be any of</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0x0000000000000000</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0x0000000000000001</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0x0000000000000002</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  ...</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0x000000007fffffff</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">or</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0xffffffff80000000</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0xffffffff80000001</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0xffffffff80000002</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  ...</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">  0xffffffffffffffff</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">however it can't ever be 0x0000000080000000, because there's no 32-bit value</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">the undef could take which sign-extends into that 64-bit value.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">Therefore, if signed add overflow returns undef, promoting such 32-bit variables to</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">64-bit variables is not a behavior-preserving transformation.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">------------------------------------------------------------------------</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">Tue Nov 29 2011  "the nsw story" (Dan Gohman)</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;"> </span>starts by describing sign-extension on LP64 targets as the</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">      </span>motivation for "nsw", in that in many situations a 32-bit add-nsw</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">     </span>can be promoted to a 64-bit add, eliminating the sext operation,</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">        </span>or at least hoisting it out of a loop where it can be expensive</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;"> </span>could also be titled "the poison story",</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">      </span>because it ends with this list of alternatives to "poison"</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">    </span>none of which seem to be acceptable to Dan, but I'm still</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">       </span>not sure how "poison" solves the LP64 sext problem</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">#<span class="Apple-tab-span" style="white-space: pre;">    </span>here are Dan's alternatives to "poison"</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">A natural reaction to this problem is to think that LLVM IR is so nice</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">and pretty that naturally there must be a nice and pretty solution. Here</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">are some alternatives that have been considered:</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> - Go back to using undef for overflow. There were no known real-world</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   bugs with this. It's just inconsistent.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> - Define add nsw as a fully side-effecting operation, and accept the</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   limits on code motion that this implies. However, as LLVM starts doing</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   profile-guided optimizations, and starts thinking about more diverse</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   architectures, code speculation will likely become more important.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> - Define add nsw as a fully side-effecting operation, and teach</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   optimization passes to strip nsw when moving code past control</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   boundaries. This is seen as suboptimal because it prevents subsequent</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   passes from making use of the nsw information. And, it's extra work</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   for optimization passes.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> - Instead of trying to define dependence in LangRef, just say that if</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   changing the value returned from an overflowing add nsw would</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   affect the observable behavior of the program, then the behavior of</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   the program is undefined. This would reduce the amount of text in</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   LangRef, but it would be a weaker definition, and it would require</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   sign-extension optimizers and others to do significantly more work</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   to establish that their transformations are safe.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> - Give up on nsw and have compilers emit warnings when they are unable</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   to perform some optimization due to their inability to exclude the</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   possibility of overflow. Obviously the warnings would not be on by</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   default, or even -Wall or probably even -Wextra, so -Werror users need</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   not revolt. Many people are often faced with code that they cannot</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   modify for any number of reasons, and would not be able to make use</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">   of such warnings. It's an interesting tradeoff, but it's unpopular.</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">Unfortunately, none of these are completely nice and pretty. Because of</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">this, and because most people don't care, nsw with all its conceptual</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">complexity has survived.</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></div></div></div></body></html>