public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/40657]  New: allocate local variables with fewer instructions
@ 2009-07-06  8:16 carrot at google dot com
  2009-07-06  8:16 ` [Bug target/40657] " carrot at google dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: carrot at google dot com @ 2009-07-06  8:16 UTC (permalink / raw)
  To: gcc-bugs

Compile following code with options -Os -mthumb -march=armv5te

extern void bar(int*);
int foo()
{
  int x;
  bar(&x);
  return x;
}

Gcc generates:

        push    {lr}
        sub     sp, sp, #12
        add     r0, sp, #4
        bl      bar
        ldr     r0, [sp, #4]
        add     sp, sp, #12
        @ sp needed for prologue
        pop     {pc}

A better code sequence could be:

        push    {r1-r3,lr}
        add     r0, sp, #4
        bl      bar
        ldr     r0, [sp, #4]
        @ sp needed for prologue
        pop     {r1-r3, pc}

The local variable allocation and deallocation can be merged into the push/pop
instruction, so we can avoid the extra sub/add instructions and reduce two
instructions.


-- 
           Summary: allocate local variables with fewer instructions
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carrot at google dot com
 GCC build triplet: i686-linux
  GCC host triplet: i686-linux
GCC target triplet: arm-eabi


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40657


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

end of thread, other threads:[~2012-06-20 18:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-06  8:16 [Bug target/40657] New: allocate local variables with fewer instructions carrot at google dot com
2009-07-06  8:16 ` [Bug target/40657] " carrot at google dot com
2009-07-06  9:14 ` steven at gcc dot gnu dot org
2009-07-06  9:55 ` ramana at gcc dot gnu dot org
2009-07-06 10:43 ` steven at gcc dot gnu dot org
2009-07-07  6:45 ` carrot at google dot com
2009-07-13 14:23 ` rearnsha at arm dot com
2009-12-22 22:53 ` ramana at gcc dot gnu dot org
2010-03-31 21:42 ` bernds at codesourcery dot com
2010-04-27  9:34 ` bernds at gcc dot gnu dot org
2010-04-27  9:36 ` bernds at gcc dot gnu dot org
2010-07-02 17:41 ` carrot at google dot com
2010-07-09  9:03 ` bernds at gcc dot gnu dot org
     [not found] <bug-40657-4@http.gcc.gnu.org/bugzilla/>
2012-06-20 18:24 ` aldot at gcc dot gnu.org
2012-06-20 18:31 ` bernds 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).