Question about inline optimization
Andrew Pinski
pinskia@physics.uc.edu
Fri Aug 6 17:57:00 GMT 2004
On Aug 6, 2004, at 8:05 AM, Arkadiusz Pawlik wrote:
> I recently wrote the following code:
> ----------x.cpp
> class C {
> public:
> double x, y;
> };
> inline double f(C a, C b) {
> return a.x * b.y - a.y * b.x;
> }
> bool g(C a, C b) {
> return f(a, b) == 0;
> }
> ---------
> Compiling with the command "g++ -O3 -S x.cpp" created a rather
> surprising output. (I have only GCC 3.3.3 on CRUX GNU/Linux for i686;
> sorry about that; maybe somebody could test it with 3.4.1)
> GCC did not optimize copying variables to stack. That is, "g()" placed
> the variables a.x, a.y, b.x, b.y on the stack with moves and then from
> the stack to fpu.
> Why does it happen? This function is performance-critical in my
> program, so optimizing the movs could be very beneficient to me.
This is fixed in 3.5.0. The reason why it does it is because GCC
(before 3.5.0) sucks when it comes
to structs and it places the struct on the stack too soon.
Thanks,
Andrew Pinski
More information about the Gcc
mailing list