Function like this: extern int bar(void); int foo(int in) { in += bar(); in += bar(); in += bar(); in += bar(); return in; } Result in putting the output of bar on stack, and adding the result just before returning. It continues on until it about 16 iteration. Meaning useless heavy stack usage and for some targets much code. The general assembler will look like this: push stack call bar put result on stack call bar put result on stack call bar put result on stack call bar add to in add stack to in add stack to in add stack to in pop stack return This behaviour is seen on recent version for arm (4.3.3), x86 (4.3.3) and avr (4.3.2). Interresting is that providing the 'register' keyword on input for -00 'solves' the problem. It seems that GCC delays the add operations until returning, however delaying beyond a function call is normally pointless and more expensive in terms of code size and cycles. See attached file for a test case with for unroll-loops and normal code.
Created attachment 17580 [details] C file showing bug compile using: gcc -S -funroll-loops -0[0123s] main.c
It'd be nice to know if -fno-tree-reassoc helped here.
(In reply to comment #2) > It'd be nice to know if -fno-tree-reassoc helped here. > Yes that solves the problem. I tried for -O[123s] (x86 and avr).
Fixed on the trunk most likely by: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49749