public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/44675]  New: Inefficient code to return a large struct
@ 2010-06-25 22:47 carrot at google dot com
  2010-06-25 22:54 ` [Bug rtl-optimization/44675] " pinskia at gcc dot gnu dot org
  2010-07-03  0:23 ` ramana at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: carrot at google dot com @ 2010-06-25 22:47 UTC (permalink / raw)
  To: gcc-bugs

Compile the following code with options -march=armv7-a -mthumb -Os

typedef struct {
  int buf[7];
} A;

A foo();
void hahaha(A* p)
{
  *p = foo();
}

GCC generates:

hahaha:
        push    {r4, r5, lr}
        sub     sp, sp, #36
        mov     r5, sp
        mov     r4, r0
        mov     r0, sp
        bl      foo
        ldmia   r5!, {r0, r1, r2, r3}
        stmia   r4!, {r0, r1, r2, r3}
        ldmia   r5, {r0, r1, r2}
        stmia   r4, {r0, r1, r2}
        add     sp, sp, #36
        pop     {r4, r5, pc}

GCC first allocates temporary memory on the stack and passes its address into
function foo, function foo will return the new struct in this memory area.
After function return, gcc copies the contents of temporary memory into another
area pointed to by pointer p. Actually we can simply pass the pointer p into
function foo, then we get

hahaha:
        /* pointer p is already in register r0 */
        /* we can also apply tail function call optimization here. */
        b      foo

Any combination of arm/thumb Os/O2 generates similar results. The inefficient
code is generated at expand pass. This may also affect other targets with
similar ABI that needs temporary memory and an extra parameter to return large
object.

Following is another similar case.

typedef struct {
  int buf[7];
} A;

A foo();
void bar(A*);
void hahaha(A* p)
{
  A t;
  t = foo();
  bar(&t);
}


-- 
           Summary: Inefficient code to return a large struct
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        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=44675


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/44675] Inefficient code to return a large struct
  2010-06-25 22:47 [Bug rtl-optimization/44675] New: Inefficient code to return a large struct carrot at google dot com
@ 2010-06-25 22:54 ` pinskia at gcc dot gnu dot org
  2010-07-03  0:23 ` ramana at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-06-25 22:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2010-06-25 22:54 -------
Related to PR 28831 and PR 44194.


-- 


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rtl-optimization/44675] Inefficient code to return a large struct
  2010-06-25 22:47 [Bug rtl-optimization/44675] New: Inefficient code to return a large struct carrot at google dot com
  2010-06-25 22:54 ` [Bug rtl-optimization/44675] " pinskia at gcc dot gnu dot org
@ 2010-07-03  0:23 ` ramana at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: ramana at gcc dot gnu dot org @ 2010-07-03  0:23 UTC (permalink / raw)
  To: gcc-bugs



-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-03 00:23:14
               date|                            |


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-03  0:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-25 22:47 [Bug rtl-optimization/44675] New: Inefficient code to return a large struct carrot at google dot com
2010-06-25 22:54 ` [Bug rtl-optimization/44675] " pinskia at gcc dot gnu dot org
2010-07-03  0:23 ` ramana at gcc dot gnu dot 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).