Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ Compiler Optimization Flags: Difference Between /O2 and /Ot

What's the difference between the /Ot flag ("favor fast code") and the /O2 flag ("maximize speed")?

(Ditto with /Os and /O1.)

like image 777
user541686 Avatar asked May 15 '11 08:05

user541686


People also ask

What does the O2 compiler flag do?

-O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.

What is O2 optimization?

The /O1 and /O2 compiler options are a quick way to set several specific optimization options at once. The /O1 option sets the individual optimization options that create the smallest code in the majority of cases. The /O2 option sets the options that create the fastest code in the majority of cases.

What does O3 compiler flag do?

-O3 instructs the compiler to optimize for the performance of generated code and disregard the size of the generated code, which might result in an increased code size. It also degrades the debug experience compared to -O2 .

What are compiler flags in C?

Compiler flags are options you give to gcc when it compiles a file or set of files. You may provide these directly on the command line, or your development tools may generate them when they invoke gcc.


2 Answers

/O1 and /O2 bundle together a number of options aimed at a larger goal. So /O1 makes a number of code generation choices that favour size; /O2 does the same thing and favours speed.

/O1 includes /Os as well as other options. /O2 includes /Ot as well as other options. Some optimisations are enabled by both /O1 and /O2. And, depending on your program's paging behaviour, /O1 (size) can result in faster speed than /O2 if paging code comes to dominate your perf over instruction execution cost.

A good short summary of the impact of /O1 and /O2 in VC++ 2010 is here

http://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx

and includes links for other versions of VC.

Martyn

like image 98
Martyn Lovell Avatar answered Sep 20 '22 02:09

Martyn Lovell


See the /O1, /O2 (Minimize Size, Maximize Speed) article at MSDN.

It states that /O2 is equivalent to:

/Og /Oi /Ot /Oy /Ob2 /Gs /GF /Gy

So /O2 enables all the things that /Ot does, and some more. Same thing for /O1 vs. /Os, but for size this time.

like image 33
Mat Avatar answered Sep 22 '22 02:09

Mat