You copied the Doc URL to your clipboard.

Optimizing for code size or performance

The compiler and associated tools use numerous techniques for optimizing your code. Some of these techniques improve the performance of your code, while other techniques reduce the size of your code.

These optimizations often work against each other. That is, techniques for improving code performance might result in increased code size, and techniques for reducing code size might reduce performance. For example, the compiler can unroll small loops for higher performance, with the disadvantage of increased code size.

By default, armclang does not perform optimization. That is, the default optimization level is -O0.

The following armclang options help you optimize for code performance:

-O0 | -O1 | -O2 | -O3
Specify the level of optimization to be used when compiling source files, where -O0 is the minimum and -O3 is the maximum.
-Ofast
Enables all the optimizations from -O3 along with other aggressive ​optimizations that might violate strict compliance with language standards.

The following armclang options help you optimize for code size:

-Os
Performs optimizations to reduce the image size at the expense of a possible increase in execution time. This option balances code size against performance.
-Oz
Optimizes for smaller code size.

Note

You can also set the optimization level with the armlink option --lto_level. The levels correspond to the armclang optimization levels.

The following armclang option helps you optimize for both code size and code performance:

-flto
Enables link time optimization, which lets the linker make additional optimizations across multiple source files.

In addition, choices you make during coding can affect optimization. For example:

  • Optimizing loop termination conditions can improve both code size and performance. In particular, loops with counters that decrement to zero usually produce smaller, faster code than loops with incrementing counters.
  • Manually unrolling loops by reducing the number of loop iterations, but increasing the amount of work done in each iteration can improve performance at the expense of code size.
  • Reducing debug information in objects and libraries reduces the size of your image.
  • Using inline functions offers a trade-off between code size and performance.
  • Using intrinsics can improve performance.
Was this page helpful? Yes No