public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33611]  New: Optimizations generate incorrect code
@ 2007-10-01 17:02 macracan at yahoo dot com
  2007-10-01 17:05 ` [Bug c++/33611] " macracan at yahoo dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: macracan at yahoo dot com @ 2007-10-01 17:02 UTC (permalink / raw)
  To: gcc-bugs

The following snipped when compiled with -O0 generates a program that quickly
finishes (correct behavior). But when compiled with any optimizations (-O1, -O2
or -O3) generates a program that never finishes. Variations on the code, (such
as the comment line) geneate valid program with either level of optimization.
Checked in 4.1.1 too (i386) and the bug is there too. Checked in 4.1.2 on
x86_64 and the bug is NOT there.

-- star of file aa.cpp
struct A
{
  unsigned int e;
};
A a = {1};
double f[] = {0.0461109, 0.285433};
int main(void)
{
  for (bool bEncore = true; bEncore; )
  {
    bEncore = false;
    double p = 0.422244 * f[a.e];
//    double p = 0.422244 * f[1];
    if (f[0] < p)
    {
      f[0] = p;
      bEncore = true;
    }
  }
  return 0;
}
-- end of file aa.cpp

g++ -O3 aa.cpp
./a.out           --> goes into infinite loop


-- 
           Summary: Optimizations generate incorrect code
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: macracan at yahoo dot com
 GCC build triplet: GNU/linux i386/i686
  GCC host triplet: GNU/linux i386/i686
GCC target triplet: GNU/linux i386/i686


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


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

* [Bug c++/33611] Optimizations generate incorrect code
  2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
@ 2007-10-01 17:05 ` macracan at yahoo dot com
  2007-10-01 17:10 ` [Bug middle-end/33611] " pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: macracan at yahoo dot com @ 2007-10-01 17:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from macracan at yahoo dot com  2007-10-01 17:05 -------
Created an attachment (id=14280)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14280&action=view)
source file and the result of 'gcc -v -save-temps -O3 aa.cpp 2>stderr'


-- 


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


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

* [Bug middle-end/33611] Optimizations generate incorrect code
  2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
  2007-10-01 17:05 ` [Bug c++/33611] " macracan at yahoo dot com
@ 2007-10-01 17:10 ` pinskia at gcc dot gnu dot org
  2007-10-01 17:16 ` [Bug middle-end/33611] [4.1/4.2/4.3 regression] " bangerth at dealii dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-10-01 17:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-10-01 17:10 -------
I think you should read http://www.validlab.com/goldberg/paper.pdf .  I think
what is happening is on x86, there is extra precision so really you are running
into bug 323.  Can you try to add -ffloat-store?


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end


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


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

* [Bug middle-end/33611] [4.1/4.2/4.3 regression] Optimizations generate incorrect code
  2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
  2007-10-01 17:05 ` [Bug c++/33611] " macracan at yahoo dot com
  2007-10-01 17:10 ` [Bug middle-end/33611] " pinskia at gcc dot gnu dot org
@ 2007-10-01 17:16 ` bangerth at dealii dot org
  2007-10-01 17:43 ` macracan at yahoo dot com
  2007-10-01 17:43 ` macracan at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2007-10-01 17:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from bangerth at dealii dot org  2007-10-01 17:16 -------
For once a real floating point bug. In this code
    double p = 0.422244 * f[a.e];
    if (f[0] < p)

with a.e=1, f[1]=0.285433, we should calculate p=0.285433. Since
f[0]=0.0461109, we shouldn't enter the if-clause, but we do when
optimization is on. Since the numbers aren't even close, this isn't
due to excess precision or any other floating point instability but
a real bug.

Funny enough, this was already broken in 2.95, 3.2.3 and 3.3.6 but then
worked in 3.4.6 and 4.0.x only to be broken again in 4.1.2.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |2.95 3.2.3 3.3.6 4.1.2
      Known to work|                            |3.4.6 4.0.4
   Last reconfirmed|0000-00-00 00:00:00         |2007-10-01 17:16:44
               date|                            |
            Summary|Optimizations generate      |[4.1/4.2/4.3 regression]
                   |incorrect code              |Optimizations generate
                   |                            |incorrect code


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


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

* [Bug middle-end/33611] [4.1/4.2/4.3 regression] Optimizations generate incorrect code
  2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
                   ` (2 preceding siblings ...)
  2007-10-01 17:16 ` [Bug middle-end/33611] [4.1/4.2/4.3 regression] " bangerth at dealii dot org
@ 2007-10-01 17:43 ` macracan at yahoo dot com
  2007-10-01 17:43 ` macracan at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: macracan at yahoo dot com @ 2007-10-01 17:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from macracan at yahoo dot com  2007-10-01 17:43 -------


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


-- 

macracan at yahoo dot com changed:

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


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


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

* [Bug middle-end/33611] [4.1/4.2/4.3 regression] Optimizations generate incorrect code
  2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
                   ` (3 preceding siblings ...)
  2007-10-01 17:43 ` macracan at yahoo dot com
@ 2007-10-01 17:43 ` macracan at yahoo dot com
  4 siblings, 0 replies; 6+ messages in thread
From: macracan at yahoo dot com @ 2007-10-01 17:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from macracan at yahoo dot com  2007-10-01 17:43 -------
(In reply to comment #3)
> For once a real floating point bug. In this code
>     double p = 0.422244 * f[a.e];
>     if (f[0] < p)
> 
> with a.e=1, f[1]=0.285433, we should calculate p=0.285433. Since
> f[0]=0.0461109, we shouldn't enter the if-clause, but we do when

Sorry, but this isn't quite accurate; the math is off, and the code _should_
enter
the if branch the first time around, just not the second time around.


-- 


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


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

end of thread, other threads:[~2007-10-01 17:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-01 17:02 [Bug c++/33611] New: Optimizations generate incorrect code macracan at yahoo dot com
2007-10-01 17:05 ` [Bug c++/33611] " macracan at yahoo dot com
2007-10-01 17:10 ` [Bug middle-end/33611] " pinskia at gcc dot gnu dot org
2007-10-01 17:16 ` [Bug middle-end/33611] [4.1/4.2/4.3 regression] " bangerth at dealii dot org
2007-10-01 17:43 ` macracan at yahoo dot com
2007-10-01 17:43 ` macracan at yahoo dot com

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