This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: c++ optimisation fails badly
- From: Teddy Todorov <Teddy dot Todorov at cern dot ch>
- To: andrewdorrell at oztralia dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 24 Jun 2004 14:24:10 +0200
- Subject: Re: c++ optimisation fails badly
- Keywords: CERN SpamKiller Note: -49 Charset: west-latin
Andrew Dorrell wrote:
> Notice in this case test 2 (user 0.564s) takes 7 times as long as test 3
> (user 0m0.074s) which performs exactly the same amount of work!
>
> Please Please Please! Am I missing something or is this a real optimiser
> problem. Is this a known issue? Am I doing something significantly wrong
> in my code? This is driving me to distraction as I am coding for image
> processing and just can't accept that kind of performance hit.
It is a known issue, and I had a similar problem. However, I _did_ manage to
get optimal performance from gcc (version 3.2.3 and later). I tried to apply
the tricks that helped me to your test case, namely
- declare the global scope operators "inline". I am not sure if the need for
this is a compiler bug.
- Add a copy constructor that does exactly what the compiler-generated one
does. This is definitely a gcc bug, and I filed a bug report (number 12685),
which turned out to duplicate a few other (see bug entry 6880), and which was
indeed fixed in gcc tree-ssa, but not in 3.3.x or 3.4.x
Adding the "inline" did speed up your example a little, but not by much.
Adding a copy constructor did not change the timing.
The only remaining difference with my code I could think of is that you use
integer arithmetics while I use floating point.
Indeed, when I converted your test to float the difference between cases 2 and
3 became small:
real 0m0.146s
user 0m0.057s
sys 0m0.083s
real 0m0.468s
user 0m0.173s
sys 0m0.284s
real 0m0.424s
user 0m0.148s
sys 0m0.264s
I guess I was lucky (and so was the Stepanov test of cost of abstraction etc.)
But this probably does not solve your problem (unless you can use a unreleased
version of gcc).
Teddy Todorov