[Bug c++/47600] gcc optimizer seems to avoid necessary floating-point addition

2011-03-08 Thread acfbuerger at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47600

Alexander Bürger acfbuerger at googlemail dot com changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution||DUPLICATE

--- Comment #6 from Alexander Bürger acfbuerger at googlemail dot com 
2011-03-08 19:08:38 UTC ---
It is a 32bit i?86 machine and my impression is that this is bug 323. The
problem disappears when ndist is stored in a volatile double.

I have not been able to produce a test case. As there seems to be a dependency
on optimization, I am probably just unlucky. I must say that I do not
understand why bug 323 should not be regarded as a bug.

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


[Bug middle-end/323] optimized code gives strange floating point results

2011-03-08 Thread acfbuerger at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

Alexander Bürger acfbuerger at googlemail dot com changed:

   What|Removed |Added

 CC||acfbuerger at googlemail
   ||dot com

--- Comment #181 from Alexander Bürger acfbuerger at googlemail dot com 
2011-03-08 19:08:38 UTC ---
*** Bug 47600 has been marked as a duplicate of this bug. ***


[Bug c++/47600] New: gcc optimizer seems to avoid necessary floating-point addition

2011-02-03 Thread acfbuerger at googlemail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47600

   Summary: gcc optimizer seems to avoid necessary floating-point
addition
   Product: gcc
   Version: 4.5.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: acfbuer...@googlemail.com


Created attachment 23237
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=23237
assembly and g++ -v output

g++ versions tested: g++-4.5 (Ubuntu/Linaro 4.5.1-7ubuntu2)  4.5.1
 g++-4.4 (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5

Problem: I have code like this:

double fakeManipulation(double d) { return d; }
...
dist = about 100
const double d = very small number, 1e-16;
const double ndist = dist+d; // does not work with optimizer
//const double ndist = fakeManipulation(dist+d); // works with optimizer
if( ndist = dist )
avoid endless loop

The comparison in the if statement is intended exactly like this: check if d is
so small that adding it to dist does not make any difference because of the
limited floating-point precision. I do not know a simpler way to do that which
is equally fast and independent of the actual values of d and dist.

When compiling this code without optimization, the comparison is handled
correctly and the endless loop is avoided.

When compiling with -O or -O2, the comparison is NOT handled correctly and the
program runs into an endless loop. With -O and -O2 and the fakeManipulation
call, it is also handled correctly.

My suspicion is that the optimizer replaces the comparison with (d=0) which is
not numerically correct. 

The full code is rather lengthy and I did not succeed to write a small
demonstration program, so I attached parts of the generated assembler code.