This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/47990] New: Missed promotion of double precision constants to single precision for -funsafe-math-optimizations
- 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: Fri, 4 Mar 2011 14:42:30 +0000
- Subject: [Bug middle-end/47990] New: Missed promotion of double precision constants to single precision for -funsafe-math-optimizations
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47990
Summary: Missed promotion of double precision constants to
single precision for -funsafe-math-optimizations
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: rguenth@gcc.gnu.org
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.