My code currently has an optimization level of 8. But i'm out of code space and want to change it to level 9. Is there any side effect if we use optimization level 9??
One side-effect of optimisation is always to reduce "debugability" - as it gets harder to see which machine instructions relate to which source line(s).
But, before applying compiler optimisations, you need to ensure that your source is optimum in the first place; for C51, see: http://www.keil.com/support/man/docs/c51/c51_xc.htm
Also, if you're needing the highest compiler optimisations, it may be an indication that you should at least be starting to think about a re-design to give you more code space...
It is a bit strange to have 11 different optimization levels. That somehow gives an indication that each optimization has a natural order or at least cost in relation to every other optimization.
Most compilers settles for maybe two or three optimization levels (little, medium and much or maybe fast, medium and expensive). This then complemented with another switch to inform the compiler if it should prioritize speed or size. And finally - for the control freaks - a full set of optimization flags to allow full customization of what optimization steps to use.
One thing interesting here is the note that the total size tends to grow at optimization levels above 9, since the documentation for lvl 10 and 11 says:
10 Rearrange Code (Linker Optimization): When detecting common block subroutines, code is rearranged to obtain larger recurring sequences. 11 Reuse of Common Exit Code (Linker Optimization): Identical exit sequences are reused. This may reduce the size of common block subroutines even further. This optimization level generates the most compact program code possible.
They are performed by the linker, so it would have been reasonable to think that the linker only performed these steps for the cases where the linker sees an actual benefit.
It is a bit strange to have 11 different optimization levels.
I suspect the marketing people were involved:
"Most compilers only have three optimisation levels. The XXXX toolchain offers eleven providing a near fourfold increase in code efficiency over lesser systems".