/Og (Global Optimizations) (original) (raw)

In this article

Deprecated. Provides local and global optimizations, automatic-register allocation, and loop optimization. We recommend you use either /O1 (Minimize Size) or /O2 (Maximize Speed) instead.

Syntax

/Og

/Og is deprecated. These optimizations are now enabled by default when any optimizations are enabled. For more information on optimizations, see /O1, /O2 (Minimize Size, Maximize Speed), or /Ox (Enable Most Speed Optimizations).

The following optimizations are available under /Og:

a = b + c;  
d = b + c;  
e = b + c;  

For local common subexpression optimization, the compiler examines short sections of code for common subexpressions. For global common subexpression optimization, the compiler searches entire functions for common subexpressions.

i = -100;  
while( i < 0 ) {  
    i += x + y;  
}  

After optimization, x + y is calculated once rather than every time the loop is executed:

i = -100;  
t = x + y;  
while( i < 0 ) {  
    i += t;  
}  

Loop optimization is much more effective when the compiler can assume no aliasing, which you set with __restrict, noalias, or restrict.
Note
You can enable or disable global optimization on a function-by-function basis using the optimize pragma together with the g option.

For related information, see /Oi (Generate intrinsic functions) and /Ox (Enable most speed optimizations).

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
  2. Select the Configuration Properties > C/C++ > Command Line property page.
  3. Enter the compiler option in the Additional Options box.

To set this compiler option programmatically

See also

MSVC Compiler Command-Line Syntax