public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/57974] std::pow(std::complex<long double>(0),1) returns  (-nan,-nan)
Date: Thu, 25 Jul 2013 15:42:00 -0000	[thread overview]
Message-ID: <bug-57974-4-CK3atAoKYb@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-57974-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57974

--- Comment #4 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Paolo Carlini from comment #3)

> I suspect the back end could be also involved because it happens only for
> long double and I didn't see anything special for long double in builtins.c

-funsafe-math-optimizations are used here:

'-funsafe-math-optimizations'

     Allow optimizations for floating-point arithmetic that (a) assume
     that arguments and results are valid and (b) may violate IEEE or
     ANSI standards.  When used at link-time, it may include libraries
     or startup files that change the default FPU control word or other
     similar optimizations.

The __builtin_expl is expanded to:

        flds    .LC0(%rip)
        fld     %st(0)
        frndint
(*)     fsubr   %st, %st(1)
        fxch    %st(1)
        f2xm1
        fadds   .LC2(%rip)
        fscale
        fstp    %st(1)
        fstpt   16(%rsp)

and with fsubr, we hit Inf - Inf, which is by definition NaN.

Obviously, this testcase exposes the unsafe part of
-funsafe-math-optimizations. Without this option everything works OK.
>From gcc-bugs-return-426718-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 25 15:47:44 2013
Return-Path: <gcc-bugs-return-426718-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 4855 invoked by alias); 25 Jul 2013 15:47:43 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 4745 invoked by uid 48); 25 Jul 2013 15:47:41 -0000
From: "paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/57974] std::pow(std::complex<long double>(0),1) returns  (-nan,-nan)
Date: Thu, 25 Jul 2013 15:47: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-Version: 4.9.0
X-Bugzilla-Keywords: wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: paolo.carlini at oracle dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P2
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57974-4-SsdvYbi6Eo@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57974-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57974-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-07/txt/msg01225.txt.bz2
Content-length: 294

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW974

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
But isn't this a bug? I mean, naively, what do we gain from the optimization
point of view from not evaluating as 0 in any case? And why it happens only for
long double?


  parent reply	other threads:[~2013-07-25 15:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-57974-4@http.gcc.gnu.org/bugzilla/>
2013-07-24 23:05 ` paolo.carlini at oracle dot com
2013-07-24 23:17 ` paolo.carlini at oracle dot com
2013-07-24 23:18 ` paolo.carlini at oracle dot com
2013-07-25 15:22 ` paolo.carlini at oracle dot com
2013-07-25 15:42 ` ubizjak at gmail dot com [this message]
2013-07-25 15:58 ` ubizjak at gmail dot com
2013-07-25 16:08 ` paolo.carlini at oracle dot com
2013-07-25 16:12 ` ubizjak at gmail dot com
2013-07-25 17:27 ` paolo.carlini at oracle dot com
2013-07-25 18:03 ` gdr at gcc dot gnu.org
2013-07-25 18:14 ` paolo.carlini at oracle dot com
2013-07-25 21:24 ` paolo.carlini at oracle dot com
2013-07-26 11:53 ` paolo.carlini at oracle dot com
2013-07-26 12:58 ` glisse at gcc dot gnu.org
2013-07-26 13:23 ` paolo.carlini at oracle dot com
2013-07-26 13:52 ` glisse at gcc dot gnu.org
2013-07-26 14:52 ` glisse at gcc dot gnu.org
2020-04-13 20:08 ` msebor at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57974-4-CK3atAoKYb@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).