public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/26214]  New: gcc -O2 creates erroneous code
@ 2006-02-10 17:12 steger at mvtec dot com
  2006-02-10 18:11 ` [Bug tree-optimization/26214] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: steger at mvtec dot com @ 2006-02-10 17:12 UTC (permalink / raw)
  To: gcc-bugs

On the following program, gcc -O2 creates incorrect code:

#include <stdio.h>


#define NUM 10000
#define MAX 10.0


__inline__ float rsqrt(float x)
{
  float xhalf = 0.5f * x;
  int i = *(int*)&x;
  i = 0x5f375a86 - (i>>1);
  x = *(float*)&i;
  x = x * (1.5f - xhalf * x * x);
  return x;
}


int main(void)
{
  int i, j;
  float x, y;

  for (i=0; i<NUM; i++)
  {
    x = (i+1)*MAX/NUM;
    y = rsqrt(x);
    fprintf(stderr,"%10.6f -> %10.6f\n",x,y);
  }
}

The same code works as expected with gcc 3.3.6.

Interestingly, if "fprintf(stderr," is changed to "printf(" the output changes
significantly, but is still incorrect.


-- 
           Summary: gcc -O2 creates erroneous code
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: steger at mvtec dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug tree-optimization/26214] gcc -O2 creates erroneous code
  2006-02-10 17:12 [Bug tree-optimization/26214] New: gcc -O2 creates erroneous code steger at mvtec dot com
@ 2006-02-10 18:11 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-10 18:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-10 18:11 -------
  x = *(float*)&i;


You are violating C aliasing rules.

*** This bug has been marked as a duplicate of 21920 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


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

end of thread, other threads:[~2006-02-10 18:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-10 17:12 [Bug tree-optimization/26214] New: gcc -O2 creates erroneous code steger at mvtec dot com
2006-02-10 18:11 ` [Bug tree-optimization/26214] " pinskia at gcc dot gnu dot org

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