
About Arm Compiler 6


AC5 and AC6

Keil MDK Optimization Options


<span>-O0</span>
Disables all optimizations. This optimization level is the default setting. Using<span>-O0</span>
results in faster compilation and build times, but the generated code is slower than that produced by other optimization levels. Compared to<span>-O0</span>
other optimization levels, the code size and stack usage are significantly higher. The generated code is closely related to the source code, but the amount of generated code is larger, including useless code.Optimization Level -O1
<span>-O1</span>
Enables core optimizations in the compiler. This optimization level provides a good debugging experience and has better code quality than<span>-O0</span>
, with improved stack usage.Arm recommends using this option for a good debugging experience.<span>-O1</span>
The differences when used compared to -O0
are:-
Enables optimizations, which may reduce the completeness of debugging information. -
Enables inlining and tail calls, which means backtraces may not provide the stack with the function activated. -
Functions that are not used or not expected to be called will not be called, resulting in smaller code size. -
The values of variables may be unavailable in their scope after they are not used. For example, their stack locations may have been reused.
Optimization Level -O2
<span>-O2</span>
Compared to -O1
, this level provides higher performance optimization. It adds some new optimizations and changes the heuristic methods for optimization. This is the first optimization level at which the compiler may generate vector instructions. It may also reduce the debugging experience.<span>-O2</span>
The differences when used compared to -O1 are:-
The threshold for the compiler to consider inlining call sites as profitable may increase. -
The number of loop unrollings performed may increase. -
Vector instructions can be generated for related sequences of simple loops and independent scalar operations.
<span>-fno-vectorize</span>
.Optimization Level -O3
<span>-O3</span>
Compared to -O2, this level provides higher performance optimization. This optimization level allows for optimizations that require extensive compile-time analysis and resources, and it changes the heuristic methods for optimization compared to -O2.<span>-O3</span>
instructs the compiler to optimize for the performance of the generated code, ignoring the size of the generated code, which may lead to an increase in code size.<span>-O3</span>
The differences when used compared to -O2 are:-
The threshold for the compiler to consider inlining call sites as profitable increases. -
The amount of loop unrolling performed increases. -
Enables more aggressive instruction optimizations in the compiler pipeline.
Optimization Level -Os
<span>-Os</span>
Aims to provide high performance without significantly increasing code size. Depending on your application, the performance provided may be similar to <span>-O2</span>
or <span>-O3</span>
.<span>-Os</span>
Compared to -O3, it reduces the code size. However, it reduces the debugging experience.<span>-Os</span>
The differences when used compared to -O3 are:-
Reduces the threshold for the compiler to consider inlining call sites as profitable. -
Significantly reduces the amount of loop unrolling performed.
Optimization Level -Oz
<span>-Oz</span>
Aims to provide the smallest possible code size. Arm recommends using this option for the best code size. This optimization level will reduce the debugging experience..<span>-Oz</span>
The differences when used compared to -Os are:-
The compiler optimizes only for code size, ignoring performance optimizations, which may slow down the code. -
Inlining is not disabled. In some cases, inlining may overall reduce code size, for example, if a function is only called once. Inlining heuristics are adjusted to inline only when a reduction in expected code size is anticipated. -
Disables optimizations that may increase code size, such as loop unrolling and loop vectorization. -
Loops are generated as while loops rather than do-while loops.
Optimization Level -Ofast
<span>-Ofast</span>
Executes optimizations from the level, including optimizations performed with the <span>-ffast-math</span>
armclang option.Optimization Level -Omax
<span>-Omax</span>
Is the maximum optimization level, specifically targeting performance optimization. It supports all optimizations performed from the level, as well as link-time optimization (LTO).———— END ————
● Column “Embedded Tools”
● Column “Embedded Development”
● Column “Keil Tutorial”
● Selected Tutorials from Embedded Column
Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.