[llvm-dev] [cfe-dev] Should isnan be optimized out in fast-math mode?

Arthur O'Dwyer via llvm-dev llvm-dev at lists.llvm.org
Wed Sep 15 10:57:56 PDT 2021


On Wed, Sep 15, 2021 at 12:42 PM Chris Tetreault <ctetreau at quicinc.com>
wrote:

> Fundamentally, the question Serge asked has nothing to do with the
> concerns of “compiler people”, and everything to do with the user facing
> behavior of the compiler. Any talk of how the behavior should be
> implemented is (in my opinion) off topic until we settle the question of
> “should the compiler guarantee, as a special case, that isnan(x) will not
> be optimized out”. This is a Yes-or-No question [...]
>

That's a good illustration of what I meant by "application level."  The
user who asks "Will my call to isnan() be 'optimized out'?" doesn't really
have any sense of what's going on at the compiler level. The compiler
person can say, "Yes, of course *some* calls to `isnan` can be eliminated"
and show them all kinds of examples:

    void one(double d) { (void)isnan(d); puts("hello world"); }
    void two(double d) { d = 2.0; if (isnan(d)) puts("this branch is
dead"); }
    void three(double d) { d *= 0.0; if (isnan(d)) puts("this branch is
dead only in fast-math mode"); }

but they don't really care about these examples; they care about one
specific use of isnan() somewhere deep inside their specific application.
We can't really give a Yes or No answer about that one because we can't see
it; all we can do is try to explain the rules by which the compiler decides
whether a given transformation is OK or not, and then the application
developer has to take those rules back home and study their own code to
figure out whether the compiler will consider the transformation OK to
apply to that code.

HTH,
Arthur

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210915/a3c1e5ad/attachment.html>


More information about the llvm-dev mailing list