<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=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">1. ————— </div><div class="">Dan,</div><div class="">       The reasoning given below for how GVN operates seems odd to me,</div><div class=""><br class=""></div><div class="">Poison is an attribute of a value,  just like nsw is an attribute of an operation,</div><div class=""><br class=""></div><div class="">So when GVN sees a pair of equal values, one of which has an extra attribute,</div><div class="">The proper choice for representative value is the one without the attribute,</div><div class=""><br class=""></div><div class="">Just like when GVN sees a pair of add operations, one of which has an extra attribute,</div><div class="">The proper choice for representative is the one without the attribute</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">2. —————</div><div class="">Nuno,</div><div class="">         If Dan agrees with the above then can we come up with a better example</div><div class="">for why branch-on-poison should be “undefined behavior”.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thoughts ?</div><div class="">Comments ?</div><div class="">Questions ?</div><div class=""><br class=""></div><div class="">Peter Lawrence.</div><div class=""><br class=""></div><div class="">-------------------------------------------------------------------------------------------</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>Nuno Lopes via llvm-dev at <a href="http://lists.llvm.org" class="">lists.llvm.org</a></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>Tue Oct 18 08:10:41 PDT 2016</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="white-space: pre-wrap;" class="">>>></span><i style="white-space: pre-wrap;" class=""> Note that having branch on poison not trigger UB has its own problems.</i></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>> Can you please elaborate on these problems?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>Sure! For example, the following transformation would be wrong if branch on poison was a non-deterministic branch instead of >UB:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span>></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    %a = add i32 %x, 1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    %c = icmp eq i32 %a, %p</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    br i1 %c, label %bb1, label %bb2</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>bb1:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    %b = add i32 %x, 1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    %d = call i32 @bar(i32 %b)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">> ------></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">> bb1:</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>    %d = call i32 @bar(i32 %p)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">>GVN will perform this kind of transformation: it concludes that %a, %b, and %p are all equal and picks one representative value. However, these values are equal only when they are not poison.  If %p is indeed poison, then the transformation is wrong because before it was passing an ok value to bar() and after the transformation it is passing poison.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">On the other hand, if branching on poison is UB, the original program was executing UB already because %p (and therefore %c) were poison. So the transformation is ok.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><span style="font-family: Helvetica; font-size: 12px;" class="">-------------------------------------------------------------------------------------------</span></div></div></div></body></html>