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?
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
I am using IAR ARM 9.60.3 workbench and i want to know:-1.What exactly this high optimization do without selecting any option available.2.Is it affect the working of my code or semantics of code
I cannot comment on IAR products. Please contact them directly.
My first response applies to Arm Compiler for Embedded (as provided with Arm Development Studio and Keil MDK).