public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "joseph at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/47990] Missed promotion of double precision constants to single precision for -funsafe-math-optimizations
Date: Fri, 04 Mar 2011 15:43:00 -0000 [thread overview]
Message-ID: <bug-47990-4-YQHSOuIkLi@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47990-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47990
--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2011-03-04 15:42:39 UTC ---
On Fri, 4 Mar 2011, rguenth at gcc dot gnu.org wrote:
> In 482.sphinx3 we have code like
>
> float foo (float x, float y)
> {
> return ((int)(x/y + 0.5)) * y;
> }
>
> where the addition of 0.5 is performed in double precision. With
> -funsafe-math-optimizations we can demote 0.5 to single precision
> (its exactly representable) also because the result of the addition
> does not take part of further floating point computation but is
> immediately converted to int.
>
> The unsafe part of this optimization occurs when x/y is FLT_MAX
> and we'd truncate to a 64bit integer type. For 32bit integers
> it would probably be safe to do this optimization unconditionally.
No, that's not safe unconditionally; consider x/y == 0x800001p0f, for
example (so adding 0.5f and converting to float results in rounding up to
the next integer in the default round-to-nearest mode, whereas conversion
from floating point to integer in C always rounds towards zero).
next prev parent reply other threads:[~2011-03-04 15:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-04 14:42 [Bug middle-end/47990] New: " rguenth at gcc dot gnu.org
2011-03-04 15:43 ` joseph at codesourcery dot com [this message]
2011-08-01 13:07 ` [Bug middle-end/47990] " rguenth at gcc dot gnu.org
2021-12-26 13:00 ` pinskia 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-47990-4-YQHSOuIkLi@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).