<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi Mehdi,</div><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 13, 2018, at 12:34 PM, Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" class="">joker.eph@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">2018-02-08 17:34 GMT-08:00 Quentin Colombet via llvm-dev<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">TL;DR</div><div class="">r317488 changed the way fast math flags are laid out in the bitcode and anyone compiling a pre-llvm-6.0 bitcode with llvm-6.0 will lose all the optimizations guarded by isFast and a pre-llvm-6.0 compiler compiling a llvm-6.0 bitcode will potentially generate incorrect code w.r.t. fast math expectations.</div><div class=""><br class=""></div><div class="">Should we bump the bitcode version because of that and have the autoupgrader properly rewrite the fast-math to preserve that semantic?</div><div class="">(I believe we should!)</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">* Context *</div><div class=""><br class=""></div><div class="">With <a href="https://reviews.llvm.org/D39304" target="_blank" class="">https://reviews.llvm.org/<wbr class="">D39304</a> / r317488 we got rid of the umbrella UnsafeMath flag and introduced 3 more flags that better represent the different things that happen under fast-math.</div><div class=""><br class=""></div><div class="">From a bitcode perspective, this change looks like this:</div><div class="">Before r317488 we had 6 bits that respectively represented:</div><div class=""><br class=""></div><div class="">UnsafeMath</div><div class="">nnan</div><div class="">ninf</div><div class="">nsz</div><div class="">arcp</div><div class="">contract</div><div class="">*unset*</div><div class=""><br class=""></div><div class="">(The order may not match what is exactly in the bitcode.)</div><div class=""><br class=""></div><div class=""><div class="">After r317488 we had 7 bits that respectively represented:</div></div><div class=""><div class="">reassoc (-UnsafeMath- is gone)</div><div class="">nnan</div><div class="">ninf</div><div class="">nsz</div><div class="">arcp</div><div class="">contract</div></div><div class="">*afn* (new bit)</div><div class=""><br class=""></div><div class="">Before r317488, fast-math was true if UnsafeMath was true (this should also imply all the other flags are sets). After r317488, fast-math is true if all the bits are set, in particular the afn, new one, too.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">* Problem *</div><div class=""><br class=""></div><div class="">Given we currently have no way to check if a bitcode file has been generated pre-r317488 or post-r317488 that means that:</div><div class="">1. a post-r317488 compiler is going to skip any optimization guarded by isFast for all pre-r317488 bitcode file (remember the afn bit is not set here)</div><div class="">2. a pre-r317488 compiler is going to run any optimization guarded by unsafeAlgebra for any post-r317488 bitcode file that has the reassoc bit (remember we repurposed UnsafeMath)</div><div class=""><br class=""></div><div class="">Scenario #2 might be unlikely but we’re potentially breaking the semantic of the program. It is particularly dangerous because there is nothing that is going to tell us that we are in this situation “downgrade" situation.</div><div class="">#1 means that any code that uses unsafeMath is going to get a performance hit.</div><div class=""><br class=""></div><div class="">In other words, one scenario implies generating wrong code and the other, runtime performance regressions.</div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class="">Scenario #1 is unsupported AFAIK, unless I missed something the bitcode is not forward compatible: loading newer bitcode with an older LLVM has never been supported as far I can remember. </div></div></div></div></blockquote><div><br class=""></div><div>I agree, but we cannot detect that this is the situation we are in and debugging would prove hard. That said, if we say we don’t care, so be it :).</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div class=""><div class=""><br class=""></div><div class="">Scenario #2 is very much like other performance regression when we drop old metadata (i.e. bitcode upgrade isn't performance proof in general but only "best effort", there have been multiple instance of this in the past).</div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div class=""><div class=""><br class=""></div><div class="">Usually IIRC we try not to version the bitcode at all this way (i.e. bitcode does not have a linear versioning that is regularly bumped) but instead make sure the encoding itself allows an easy upgrade. I.e. the encoding of the FMF should have been such that the reader can detect and upgrade to the new IR representation. </div><div class="">Now this is too late here I guess, so bumping may be a possible trade-off.</div></div></div></div></blockquote><div><br class=""></div><div>Do you think we should do it, or live with the performance drop?</div><div>I know this performance drop is not acceptable for our use cases, but I don’t want to impose our ruling on this.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div class=""><div class="">What about any bitcode shipped after r317488 but before the version bump? Not worth taking into account because of the short period of time?</div></div></div></div></blockquote><div><br class=""></div><div>I was hoping we can ignore that period of time because it was not in any official LLVM release.</div><div><br class=""></div><div>Best,</div><div>-Quentin</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div class=""><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">-- </div><div class="">Mehdi</div></div><div class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="word-wrap: break-word; line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">* Feedback Needed *</div><div class=""><br class=""></div><div class="">I believe this change is big enough that it would be worth bumping the bitcode version so that the upgrader can do the right thing *before* we release it to the public with LLVM-6.0.</div><div class=""><br class=""></div><div class="">That being said, I don’t know what are the implications of such bump and if people really don’t care about the performance problem that might be okay. The silent downgrade path is however concerning.</div><div class=""><br class=""></div><div class="">Should we bump the bitcode version because of that change and have the autoupgrader properly rewrite the fast-math flags to </div><div class="">preserve the semantic and make sure there are no silent downgrade?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">-Quentin</div></div><br class="">______________________________<wbr class="">_________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a></blockquote></div></div></blockquote></div><br class=""></body></html>