C/C++ Compiler (cl.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Maximum Optimization (/Ox)
                                             Up Contents Index Back
─────C/C++ Compiler─────────────────────────────────────────────────────────
 
     Syntax:  /Ox
 
     The /Ox option is a shorthand way to combine optimizing options to
     produce the fastest possible program. The /Ox option is equivalent
     to a combination of the following options:
 
     Option     Compiler Action
 
     /Oc        Enables local common subexpression optimization
     /Oe        Performs global register allocation
     /Og        Enables global-level common subexpression optimization
     /Oi        Generates intrinsics for certain functions
     /Ol        Performs safe loop optimizations
     /On        Disables unsafe loop optimizations
     /Oo        Enables post code-generation optimizing
     /Ot        Favors execution time over code size
     /Gs        Removes stack probes
 
     The command-line equivalent of /Ox is /Ocegilnot /Gs. With the
     p-code (/Oq) option, both the /Ov and the /Of options are enabled.
 
     For the fastest possible program, use the following options in
     addition to /Ox:
 
     Option     Compiler Action
 
     /Oa        Assumes no aliasing
     /Oz        Performs maximum loop and global-register-allocation
                optimizations
     /Ob2       Expands functions marked as inline or __inline and any
                other function the compiler chooses (expansion occurs at
                compiler discretion)
     /Gr        Uses fastcall calling convention
 
     The options above enable code-movement and parameter-passing
     optimizations not available with /Ox alone. Although /Ozaxb2 /Gr
     works with the majority of programs, some programs do not work
     properly when compiled with these options.
 
     If a program fails to compile with maximum optimization (/Ozaxb2
     /Gr), first make sure the code executes correctly without any
     optimization. If it does, try compiling without /Oa or /Oz. If
     there are still problems, specify the optimizations you need
     individually, eliminating the ones that break your code.
 
     For the smallest possible program, use the following options:
 
     Option     Compiler Action
 
     /Oa        Assumes no aliasing
     /Os        Minimizes the size of executable files
     /Oe        Ignores the register keyword and store the value of
                frequently used variables and subexpressions in
                registers
     /Gs        Removes stack probes
 
     NOTES:
 
        ■ If you get divide-by-zero or infinite-loop errors when
          compiling with the /Oz option, try compiling without it.
 
        ■ The __fastcall calling convention requires that you provide
          function prototypes for external functions. Until you provide
          these prototypes, consider compiling without the /Gr option.
 
     See also: Removing Stack Probes
               C Calling Convention (/Gd)
               Fastcall Calling Convention (/Gr)
               Pascal Calling Convention (/Gc)
                                    -♦-