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.
armclang does not perform
optimization. That is, the default optimization level is
armclang options help
you optimize for code performance:
- Specify the level of optimization to be used when compiling
source files, where
-O0is the minimum and
-O3is the maximum.
- Enables all the optimizations from
-O3along with other aggressive optimizations that might violate strict compliance with language standards.
armclang options help
you optimize for code size:
- Performs optimizations to reduce the image size at the expense of a possible increase in execution time. This option balances code size against performance.
- Optimizes for smaller code size.
NoteYou can also set the optimization level with the armlink option
--lto_level. The levels correspond to the armclang optimization levels.
armclang option helps
you optimize for both code size and code performance:
- 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.