User account creation filtered due to spam.

Bug 33675 - Badly optimized negations on x86 with -frounding-math
Summary: Badly optimized negations on x86 with -frounding-math
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.1.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: missed-optimization
Depends on:
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.