This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question about inline optimization
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: Arkadiusz Pawlik <apawlik at V-LO dot krakow dot pl>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 6 Aug 2004 08:19:07 -0700
- Subject: Re: Question about inline optimization
- References: <Pine.LNX.4.60.0408061656480.6485@august.V-LO.krakow.pl>
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