Compiler option: Optimization

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi all,

option O3 is now working for me. As suggested in microcontroller.net I added the option -fno-gcse. Code size reduced by ~25%.

From microcontroller,.net: (Sorry in German):
Beim Einsatz des gcc in Verbindung mit in C geschriebenem startup-Code bei den Optimierungslevels "-O2" und "-O3" muss zusätzlich "-fno-gcse" gesetzt werden, da ansonsten die von der CPU benötigte NVIC-Tabelle(n) und zugehörige Funktionen u.U. nicht so aussehen wie sie sollten.

Regards
Kurt
0 Likes
3 Replies
Not applicable
Hi Kurt,

Thanks for the great tips..
I think this helps our forum community a lot..
0 Likes
User6412
Level 4
Level 4
For my project:

without "-fno-gcse"
text data bss dec hex
110592 8600 21956 141148 2275c

with "-fno-gcse"
text data bss dec hex
117552 8600 21956 148108 2428c
So, it's 4.9% bigger...
About performance I don't know.
0 Likes
User7795
Level 4
Level 4
Hi Dmitry,

the GCC manual tells you:
-fno-gcse:
"Perform a global common subexpression elimination pass. This pass also per-
forms global constant and copy propagation.
Note: When compiling a program using computed gotos, a GCC extension,
you may get better run-time performance if you disable the global common
subexpression elimination pass by adding ‘-fno-gcse’ to the command line.
Enabled at levels ‘-O2’, ‘-O3’, ‘-Os’."
(end of citation)

There are only a few special situations, where disabling switch -gcse results in an advantage, because you reduce the optimization possibilities of the gcc. One advantage could be shorter runtime of computed gotos used at interrupt jump tables needed if you write the startup code by yourself in C. But each newer version of the gcc behaves possibly different and the tip could be obsolete, you have to test it. And notice: when using DAVE CE projects Infineon is generating the startup file for you as assembler file startup_XMC4500.s (for XMC4500) which isn't affected by this switch.
In most cases you will get only larger code because of switched off subexpression elimination and global constant and copy propagation. To check the effect you can also look on the assembler code generated by DAVE in file .lst in directory 'Debug'.
0 Likes