# Methods to Optimize Code Size

This section provides some guidance on how to achieve smaller object and smaller executable size when using the optimizing features of Intel compilers.

To begin, there are two compiler options that are designed to prioritize code size over performance:

Favors size over speed | Linux* and macOS*: -Os Windows*: /Os | This option enables optimizations that do not increase code size; it produces smaller code size than option O2. Option Os disables some optimizations that may increase code size for a small speed benefit.
Minimizes code size | Linux* and macOS*: -O1 Windows*: /O1 | Compared to option Os, option O1 disables even more optimizations that are generally known to increase code size. Specifying option O1 implies option Os. As an intermediate step in reducing code size, you can replace option O3 with option O2 before specifying option O1. Option O1 may improve performance for applications with very large code size, many branches, and execution time not dominated by code within loops.

For more information about the above options, see their full descriptions in the Compiler Reference.

The rest of this section briefly discusses methods that may help you further improve code size even when compared to the default behaviors of options Os and O1.

The following table shows the methods for code size optimization that are summarized in this section.

Disable or Decrease the Amount of Inlining
Strip Symbols from Your Binaries
Dynamically Link Intel-Provided Libraries
Exclude Unused Code and Data from the Executable
Disable Recognition and Expansion of Intrinsic Functions
Optimize Exception Handling Data on Linux and macOS* Systems
Disable Passing Arguments in Registers Instead of On the Stack
Disable Loop Unrolling
Disable Automatic Vectorization
Avoid References to Compiler-Specific Libraries
Avoid Unnecessary 16-Byte Alignment
Use Inter-Procedural Optimization (IPO)

For more information about compiler options that are mentioned in the above topics, see their full descriptions in the Compiler Reference.

Things to remember:

- Some of these methods may already be applied by default when options Os and O1 are specified. All the methods mentioned in subsequent topics can be applied at higher optimization levels.

- Some of the options referred to in these topics will not necessarily cause code size reduction, and they may provide varying results (good, bad, or neutral) based on the characteristics of the target code. Still, these are the recommended things to try to see if they cause your binaries to become smaller while maintaining acceptable performance.

Parent topic: Optimization and Programming Guide

- Disable or Decrease the Amount of Inlining
- Strip Symbols from Your Binaries
- Dynamically Link Intel-Provided Libraries
- Exclude Unused Code and Data from the Executable
- Disable Recognition and Expansion of Intrinsic Functions
- Optimize Exception Handling Data (Linux* and macOS*)
- Disable Passing Arguments in Registers Instead of On the Stack
- Disable Loop Unrolling
- Disable Automatic Vectorization
- Avoid References to Compiler-Specific Libraries
- Avoid Unnecessary 16-Byte Alignment
- Use Inter-Procedural Optimization (IPO)

## See Also

O compiler option
Os compiler option