This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimized program four times slower.
- From: Nick Maclaren <nmm1 at cus dot cam dot ac dot uk>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 14 Jul 2007 22:04:23 +0100
- Subject: Re: Optimized program four times slower.
"Sebastien M." <ploouuf@yahoo.fr> wrote:
>
> I have a strange behaviour when I compile my program with -O2: it becomes slower
It isn't rare. The only way to find out for sure is to print the
assembler, work out EXACTLY where everything is located and check
it all carefully. You need to know a lot about computer architecture
to do the analysis, too.
Generally, it is due to a cache problem or similar. The alignment
changes, and one of the codes has to reload a couple of locations
each time round the loop. You can often make this phenomenon go
away (or appear!) by adding a completely irrelevant statement
elsewhere in the code.
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679