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
4.1.2
: P3 enhancement
: ---
Assigned To: Not yet assigned to anyone
: missed-optimization
Depends on:
Blocks:
  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:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-10-08 08:53:42


Attachments

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)
        fchs
        movl    8(%ebp), %eax
        fstps   -20(%ebp)
        flds    -20(%ebp)
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fchs
        fstps   (%eax)

insted of simply

        fldl    12(%ebp)
        fchs
        fstps   -4(%ebp)
        flds    -4(%ebp)
        fchs
        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.