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.
--
Summary: Delaying operation to end of function causes high stack
usage
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wvangulik at xs4all dot nl
GCC host triplet: linux-x86
GCC target triplet: multiple (at least: arm, x86, avr)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39621