<div dir="ltr"><div dir="ltr">On Mon, Sep 20, 2021 at 1:11 PM Aaron Ballman via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-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">On Mon, Sep 20, 2021 at 1:04 PM Mehdi AMINI via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> I'd find it unfortunate though that in a mode which specifies that the result of floating point arithmetic can't have NaN we can't constant fold isnan(x) where x is a potentially complex expression (think that x could be dead-code if not for the isnan).<br>
<br>
I think part of my concern is with the "result of floating point<br>
arithmetic can't have NaN" statement. I consider this case:<br>
<br>
if (isnan(foo / bar)) {}<br>
<br>
to be fundamentally different from this case:<br>
<br>
if (isnan(foo)) {}<br>
<br>
because the first example can never result in the if branch being<br>
taken with -ffinite-math-only while the second example can.</blockquote><div><br></div><div>Mehdi's statement is consistent with your interpretation, yes. In the first case, "foo / bar" is the result of floating-point arithmetic. In the second case, "foo" is not the result of floating-point arithmetic — or at least, you didn't demonstrate that it was.</div><div><br></div><div>Of course if the preceding line was</div><div><br></div><div> foo = foo / bar;</div><div> if (isnan(foo)) {}</div><div><br></div><div>then we can constant-fold `isnan(foo)` to false, as Mehdi said, because `foo`'s value is the result of floating-point arithmetic.</div><div><br></div><div>HTH,</div><div>–Arthur</div></div></div>