public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39621]  New: Delaying operation to end of function causes high stack usage
@ 2009-04-03  8:47 wvangulik at xs4all dot nl
  2009-04-03  8:49 ` [Bug c/39621] " wvangulik at xs4all dot nl
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: wvangulik at xs4all dot nl @ 2009-04-03  8:47 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <bug-39621-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-12-30  6:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03  8:47 [Bug c/39621] New: Delaying operation to end of function causes high stack usage wvangulik at xs4all dot nl
2009-04-03  8:49 ` [Bug c/39621] " wvangulik at xs4all dot nl
2009-04-06 17:16 ` hp at gcc dot gnu dot org
2009-04-07  7:55 ` wvangulik at xs4all dot nl
2009-04-30  7:54 ` [Bug tree-optimization/39621] " ramana at gcc dot gnu dot org
     [not found] <bug-39621-4@http.gcc.gnu.org/bugzilla/>
2011-12-30  6:11 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).