public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: gsasha@cs.technion.ac.il
To: gcc-gnats@gcc.gnu.org
Subject: optimization/9840: Incorrect optimization for floating-point aliasing to int
Date: Mon, 24 Feb 2003 21:26:00 -0000	[thread overview]
Message-ID: <20030224211606.15474.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2003-02-24 21:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-24 21:26 gsasha [this message]
2003-02-24 21:59 bangerth

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=20030224211606.15474.qmail@sources.redhat.com \
    --to=gsasha@cs.technion.ac.il \
    --cc=gcc-gnats@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).