GCC Bugzilla will be upgraded from version 4.4.9 to 5.0rc3 on Saturday, April 25, starting around 17:00 UTC. The upgrade process should only last a few minutes. Check bug 64968 for details.
Bug 33675 - Badly optimized negations on x86 with -frounding-math
Badly optimized negations on x86 with -frounding-math
Status: NEW
Product: gcc
Classification: Unclassified
Component: middle-end
: P3 enhancement
: ---
Assigned To: Not yet assigned to anyone
: missed-optimization
Depends on:
  Show dependency treegraph
Reported: 2007-10-06 09:49 UTC by bagnara
Modified: 2007-10-08 08:53 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2007-10-08 08:53:42


Note You need to log in before you can comment on or make changes to this bug.
Description bagnara 2007-10-06 09:49:38 UTC
If you compile the function

void assign2(float* a, double b) {
  volatile float v = -b;
  *a = -v;

you will see that GCC 4.1.2, e.g., at -O2, produces

        fldl    12(%ebp)
        movl    8(%ebp), %eax
        fstps   -20(%ebp)
        flds    -20(%ebp)
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fstps   (%eax)

insted of simply

        fldl    12(%ebp)
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fstps   (%eax)
Comment 1 Andrew Pinski 2007-10-06 11:45:12 UTC
That is becasue there is a cast to volatile float which causes an extra store.
Comment 2 bagnara 2007-10-06 13:03:53 UTC
I don't understand.  Do you mean that what I consider the natural compilation of that piece of code (the shorter assembly listing) is incorrect?  In other words: do you think that the shorter assembly listing does not properly honor the volatile qualifier?
If so, why?
Comment 3 Richard Biener 2007-10-08 08:53:42 UTC
The first store is for the truncation to float, the second store is because
of the volatile.  Now we could combine the first into the second, but in
general we don't care too much to try optimize code which uses volatile.