From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20738 invoked by alias); 16 Oct 2011 10:00:26 -0000 Received: (qmail 20727 invoked by uid 22791); 16 Oct 2011 10:00:25 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 16 Oct 2011 10:00:11 +0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/50724] isnan broken by -ffinite-math-only in g++ Date: Sun, 16 Oct 2011 10:00:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg01509.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50724 --- Comment #16 from Richard Guenther 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).