how about performance of the program compiled by -O2 other than -Os?

Ian Lance Taylor iant@google.com
Fri Jun 13 14:03:00 GMT 2008


Brian Dessent <brian@dessent.net> writes:

> PRC wrote:
>
>> How about performance of the program compiled by -O2 other than -Os?
>> I think -O2 will be better than -Os? But I am not sure how better.
>
> It's impossible to answer such a vague question, as it depends on the
> target architecture, the version of gcc, and most significantly the
> nature of the code.  You can only answer these kinds of questions with a
> testcase, but I would not rule out -Os being faster in some
> circumstances and on some architectures due to more code fitting in the
> cache or better locality.

This is correct.  I'll just add that -Os is the same as -O2, except
that when there is a tradeoff between space and time -Os prefers space
and -O2 prefers time.  As these are heuristic tradeoffs, it is
entirely possible that -Os will generate faster code in some cases.

Ian



More information about the Gcc-help mailing list