<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div style="direction: inherit;"><br></div><br>Sent from my iPhone</div><div><br>On Sep 9, 2016, at 10:40 PM, Chris Lattner <<a href="mailto:clattner@apple.com">clattner@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 9, 2016, at 3:27 PM, Steve Canon via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""><div style="direction: inherit;" class=""><br class=""></div><br class="">Sent from my iPhone</div><div class=""><br class="">On Sep 9, 2016, at 6:21 PM, Abe Skolnik <<a href="mailto:a.skolnik@samsung.com" class="">a.skolnik@samsung.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><span class="">On 09/09/2016 04:31 PM, Stephen Canon wrote:</span><br class=""><span class=""></span><br class=""><blockquote type="cite" class=""><span class="">Gating this on -Owhatever is dangerous, .  We should simply default to the pragma “on” state universally.</span><br class=""></blockquote><span class=""></span><br class=""><span class="">Why so?  [honestly asking, not arguing]</span><br class=""><span class=""></span><br class=""><span class="">My guess: b/c we don`t want programs to give different results when compiled at different "-O<...>" settings with the exception of "-Ofast".</span></div></blockquote><div style="direction: inherit;" class=""><br class=""></div><div style="direction: inherit;" class="">Pretty much.  In particular, imagine a user trying to debug an unexpected floating point result caused by conversion of a*b + c into fma(a, b, c).</div></div></div></blockquote><br class=""></div><div>I think that’s unavoidable, because of the way the optimization levels work.  Even fma contraction is on by default (something I’d like to see), at -O0, we wouldn't be doing contraction for:</div><div><br class=""></div><div>auto x = a*b;</div><div>auto y = x+c;</div><div><br class=""></div><div>but we would do that at -O2 since we do mem2reg on x.</div></blockquote><div style="direction: inherit;"><br></div><div style="direction: inherit;">In C, we don't contract (the equivalent of) this unless we're passed fp-contract=fast.  The pragma only licenses contraction within a statement.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">IIRC, the situation in C++ is somewhat different, and the standard allows contraction across statement boundaries, though I don't think we take advantage of it at present.</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">You're definitely correct that there will still be differences; e.g.:</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">    x = a*b + c;</div><div style="direction: inherit;">    y = a*b;</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">It might be that at some optimization level we prove y is unused / constant / etc.  When targeting a machine where fma is costlier than mul, we generate mul+add in one case and fma in the other.  These cases are necessarily rarer than if we gate it on optimization level, however.  (And we want the perf win for -O0 anyway).</div><div style="direction: inherit;"><br></div><div style="direction: inherit;">TLDR: yeah, let's do this.</div></body></html>