<div dir="ltr"><div dir="ltr">On Wed, Sep 8, 2021 at 11:04 AM Chris Tetreault via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="gmail-m_1648894225367412798WordSection1">
<p class="MsoNormal">Of course, this all sounds fine and well, but the reality is that people don't read docs and don't make good life choices. They turn on fast math because they want it to reduce `x * 0` to `0`, and are surprised when their NaN handling code
 fails. This is unfortunate, but I don't think we should reduce the effectiveness of fast-math because of this human issue. Other flags exist for these users, and when they complain they should be told about them. Really this is an issue of poor developer discipline,
 and if we really want to solve this, perhaps some sort of "fast math sanitizer" can be created. It can statically analyze code and complain when it sees things like `if (isnan(foo))` not guarded by `__FAST_MATH__` with fast math enabled. Or, maybe the compiler
 can just issue a warning unconditionally in this case.</p></div></div></blockquote><div><br></div><div>A "fast math sanitizer" sounds like a GREAT idea.</div><div><br></div><div>Also, I'd say that if -ffast-math is on, and -fsanitize=undefined, then the UB detection should already be doing this.</div><div><br></div><div>One caveat, though.  Suppose there is code like this:</div><div><br></div><div><font face="monospace">if (d == std::numeric_limits<double>::infinity()) {</font></div><div><br></div><div>Does the comparison against infinity count as UB, since the compiler is allowed to assume there are no infinite fp values?  I hope not, or an optimization I'm about to check in will have to be reverted.</div><div><br></div><div>-- Jorg</div><div> </div></div></div>