Optimized program four times slower.
Nick Maclaren
nmm1@cus.cam.ac.uk
Sat Jul 14 21:04:00 GMT 2007
"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
More information about the Gcc-help
mailing list