This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/50724] isnan broken by -ffinite-math-only in g++
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 16 Oct 2011 09:59:35 +0000
- Subject: [Bug middle-end/50724] isnan broken by -ffinite-math-only in g++
- Auto-submitted: auto-generated
- References: <bug-50724-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50724
--- Comment #16 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-16 09:59:35 UTC ---
(In reply to comment #14)
> Richard said:
> > The documentation states
> > "Allow optimizations for floating-point arithmetic that
> > assume that arguments and results are not NaNs or +-Infs."
>
> Yes, that's my argument as well. Note ARITHMETIC. Also note MATH in the name
> of both --finite-MATH-only, and -ffast-MATH it falls under. And it doesn't
> reference the 'math library' to qualify that.
>
> Basically, if you want to close on this point, I want to see you explicitly
> argue why the classification functions should be considered arithmetic.
>
> I'm going to nail this down and list there are 5 classification functions
> (fpclassify, infinite, isinf, isnan, isnormal) and the vast majority of the
> other library functions are obviously proper arithmetic operations. The ones
> that aren't (signbit, copysign, nextafter, nan), you're exactly right that we
> should carefully consider the result of NaN optimization ("special cases").
> You don't have to do this if *you* don't want to, but it should be done and it
> sounds like no one has.
>
> > This has been discussed to death already, and the present behavior is how
> > GCC behaved since ever.
>
> Except also NOT TRUE. It currently doesn't behave this way with math.h.
math.h is not part of GCC, if math.h implements isnan in a way that skips
GCC (by making it use inline assembler) then that doesn't show GCC does
not perform the optimization (you can check with using __builtin_isnan
instead of isnan).
The only way out I see that not breaks other users uses would be a new
flag, like -fpreserve-ieee-fp-classification that, ontop of -ffinite-math-only,
would disable the optimization for the classification functions.
(Note that they are folded to arithmetic, !(x==x), so that transform has
to be disabled as well, and on some architectures you might get library
calls because of this instead of inline expansions).