This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Optimization of code for stm32wle5

I am performing compiler optimization by changing the optimization level from 'None' to 'High' and using the 'Size' option, but without enabling any of the additional checkboxes (like function inlining, loop unrolling, etc.). Despite that, my code size reduces by up to 30%. What exactly does the compiler do behind the scenes to achieve this size reduction, even though I haven’t selected any of the additional optimization options? 

Parents
  • Exactly which optimizations apply, and at which optimization level, will depend a number of factors the compiler considers when deciding how to optimize.

    I can say that "None" (-O0) does indeed mean NO optimization, and as such the code will be very poor, performance / size wise. It is typically only used for debug purposes to help ensure that the code is functionally correct. Higher optimizations levels are typically used for production code.

    The difference in size between -O1, -O2, and -O3 should be more subtle. Additional options, such as link time optimization, as well as tuning for size/performance will also affect the output.

    In the (trivial) example shown in the documentation, the function goes from 11 to just 2 instructions from -O0 to -O1, simply by the removal of redundant code:

    https://developer.arm.com/documentation/100748/0624/Using-Common-Compiler-Options/Selecting-optimization-options

Reply
  • Exactly which optimizations apply, and at which optimization level, will depend a number of factors the compiler considers when deciding how to optimize.

    I can say that "None" (-O0) does indeed mean NO optimization, and as such the code will be very poor, performance / size wise. It is typically only used for debug purposes to help ensure that the code is functionally correct. Higher optimizations levels are typically used for production code.

    The difference in size between -O1, -O2, and -O3 should be more subtle. Additional options, such as link time optimization, as well as tuning for size/performance will also affect the output.

    In the (trivial) example shown in the documentation, the function goes from 11 to just 2 instructions from -O0 to -O1, simply by the removal of redundant code:

    https://developer.arm.com/documentation/100748/0624/Using-Common-Compiler-Options/Selecting-optimization-options

Children