You copied the Doc URL to your clipboard.

Selecting optimization options

Arm® Compiler performs several optimizations to reduce the code size and improve the performance of your application. However, optimization techniques can result in the loss of debug information, increased build time, or increase in image size. Optimization levels are always a trade-off between these three parameters.

Arm Compiler provides optimization options for the different optimization trade-offs. Primarily, you can optimize for performance or for image size. However, there are several options for finer control of the optimizations techniques. The optimization options are:

-O0
This is the default optimization setting. It turns off most optimizations, and gives the best correlation between the built image and your application source code.

Use the following options to optimize performance:

-O1
This results in more optimizations for performance, when compared to -O0. It also reduces the information available for debugging, and might result in an increased image size. Arm recommends this option for debugging.
-O2
This results in more optimizations for performance, when compared to -O1. It also reduces the information available for debugging, and might result in an increased image size.
-O3
This results in more optimizations for performance, when compared to -O2. It also reduces the information available for debugging, and might result in an increased image size.
-Ofast
This results in more optimizations for performance, when compared to -O3. It also reduces the information available for debugging, and might result in an increased image size. At this optimization level, Arm Compiler might violate certain language standards.
-Omax
This results in more optimizations for performance, when compared to -Ofast. It also reduces the information available for debugging, and might result in an increased image size. At this optimization level, Arm Compiler might violate certain language standards. Arm recommends this option for best performance.

Use the following options to optimize for size:

-Os
This results in reduced code size, and also reduces the information available for debugging. Using this option might make your code slower.
-Oz
This results in more reduced image size, when compared to -Os, and also reduces the information available for debugging. Using this option is likely to make your code slower than -Os. Arm recommends this option for best code size.

The example shows the optimization performed with the -O1 optimization option. To perform this optimization, compile your source file using:

armclang --target=arm-arm-none-eabi -march=armv7-a -O1 -c -S file.c

Table 2-2 Optimization example

Source code in file.c Optimized output from armclang
int dummy()
{
    int x=10, y=20;
    int z;
    z=x+y;
    return 0;
}
dummy:
    .fnstart
    movs r0, #0
    bx lr

The example shows the optimization performed with the -O0 optimization option. To perform this optimization, compile your source file using:

armclang --target=arm-arm-none-eabi -march=armv7-a -O0 -c -S file.c

Table 2-3 Optimization example

Source code in file.c Unoptimized output from armclang
int dummy()
{
    int x=10, y=20;
    int z;
    z=x+y;
    return 0;
}
dummy:
    .fnstart
    .pad #12
     sub     sp, sp, #12
     mov     r0, #10
     str     r0, [sp, #8]
     mov     r0, #20
     str     r0, [sp, #4]
     ldr     r0, [sp, #8]
     add     r0, r0, #20
     str     r0, [sp]
     mov     r0, #0
     add     sp, sp, #12
     bx	 lr
Was this page helpful? Yes No