public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/9840: Incorrect optimization for floating-point aliasing to int
@ 2003-02-24 21:59 bangerth
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth @ 2003-02-24 21:59 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gsasha, nobody

Synopsis: Incorrect optimization for floating-point aliasing to int

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Mon Feb 24 21:58:59 2003
State-Changed-Why:
    Not a bug. You are violating aliasing rules, so the compiler
    may generate whatever code it likes. If you need to play
    type games, check the manual for ways to do that.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9840


^ permalink raw reply	[flat|nested] 2+ messages in thread

* optimization/9840: Incorrect optimization for floating-point aliasing to int
@ 2003-02-24 21:26 gsasha
  0 siblings, 0 replies; 2+ messages in thread
From: gsasha @ 2003-02-24 21:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9840
>Category:       optimization
>Synopsis:       Incorrect optimization for floating-point aliasing to int
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 21:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Alex Gontmakher
>Release:        gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-2mdk)
>Organization:
>Environment:
machine: Athlon MP 1800
>Description:
The following code worked with previous versions of GCC, producing either 1 or 0. Now it produces 2.

A workaround is to uncomment the printf() line - obviously causes it to perform the initialization of the float prior to executing the ifs.

The problem happens only at optimization level O2 or higher.
>How-To-Repeat:
#include <iostream>

int f()
{
  int *p;
  double x = 1.0;
  /*fprintf(stderr,"");*/
  /* NOTE: this check assumes IEEE floating point format */
  p = (int *)&x;
  if (*p == 0)
    return 0;
  else if (*p == 0x3ff00000)
    return 1;
  else
    return 2;
}

int main()
{
  std::cout << f() << std::endl;
}
>Fix:
I didn't read the optimization code for this, but it should probably notice that p aliases &x, and perform the initialization of x prior to reading *p.
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-24 21:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-24 21:59 optimization/9840: Incorrect optimization for floating-point aliasing to int bangerth
  -- strict thread matches above, loose matches on Subject: below --
2003-02-24 21:26 gsasha

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).