Bug 47282 - GCC 4.2.4 (Ubuntu) gives different result for the same computation with -O3, depending on irrelevant code
Summary: GCC 4.2.4 (Ubuntu) gives different result for the same computation with -O3, ...
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-13 21:52 UTC by Igor Chudov
Modified: 2011-01-13 22:06 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
tstdouble.cpp -- compile with gcc-4.2 -O3 -o tstdouble tstdouble.cpp (1.04 KB, text/x-c++src)
2011-01-13 21:52 UTC, Igor Chudov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Chudov 2011-01-13 21:52:29 UTC
Created attachment 22961 [details]
tstdouble.cpp -- compile with gcc-4.2 -O3 -o tstdouble tstdouble.cpp

The attached C++ code depends only on stdio.h and string.h.

It calls the same function (DoubleToInt) twice: once from main( ... ) and once from Test( ... ). 

Both main() and Test() call DoubleToInt with exact same values of v and factor. 

DoubleToInt include some junk code surrounded by "if( False() ) { ... }". That junk code, though it never executes, has the effect of altering the result of calling DoubleToInt, so the second call's result does not match the first call's result. 

Even taking out a couple of lines from the big condition of if statement inside if( False() ) { ... }, causes the values to become correct.

Similarly, taking out printf in DoubleToInt, also causes the printed values to be correct (identical). 

So some flakiness exists in computations, depending on irrelevant code that never executes. We tried very hard to distill it into smallest possible code. 

This seems to NOT occur in GCC 4.3 and GCC 4.4. It only occurs with -O3.

To compile: 

   gcc-4.2 -O3 -o tstdouble tstdouble.cpp
Comment 1 Andrew Pinski 2011-01-13 21:55:05 UTC
What target are you doing your tests on?
Comment 2 Igor Chudov 2011-01-13 22:00:31 UTC
(In reply to comment #1)
> What target are you doing your tests on?

This is a 32 bit Ubuntu machine, so target -s -m32.

Thanks!

Igor
Comment 3 Igor Chudov 2011-01-13 22:01:12 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > What target are you doing your tests on?
> 
> This is a 32 bit Ubuntu machine, so target -s -m32.
> 
> Thanks!
> 
> Igor

It is a 32 bit i386 machine.
Comment 4 Andrew Pinski 2011-01-13 22:06:14 UTC
The problem is excessive percussion.

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