Potential fix for rdar://4658012

Richard Guenther richard.guenther@gmail.com
Sat Aug 26 19:26:00 GMT 2006


On 26 Aug 2006 11:12:03 -0700, Ian Lance Taylor <iant@google.com> wrote:
> "Richard Guenther" <richard.guenther@gmail.com> writes:
>
> > Instead the following patch makes the C testcase above share the stack
> > slot.  (completely untested)
> >
> > Richard.
> >
> > Index: calls.c
> > ===================================================================
> > *** calls.c     (revision 116273)
> > --- calls.c     (working copy)
> > *************** expand_call (tree exp, rtx target, int i
> > *** 1985,1991 ****
> >             /* For variable-sized objects, we must be called with a target
> >                specified.  If we were to allocate space on the stack here,
> >                we would have no way of knowing when to free it.  */
> > !           rtx d = assign_temp (TREE_TYPE (exp), 1, 1, 1);
> >
> >             mark_temp_addr_taken (d);
> >             structure_value_addr = XEXP (d, 0);
> > --- 1985,1991 ----
> >             /* For variable-sized objects, we must be called with a target
> >                specified.  If we were to allocate space on the stack here,
> >                we would have no way of knowing when to free it.  */
> > !           rtx d = assign_temp (TREE_TYPE (exp), 0, 1, 1);
> >
> >             mark_temp_addr_taken (d);
> >             structure_value_addr = XEXP (d, 0);
>
> I expect that would fail for something like
>
> typedef struct { char x[1000]; } S;
> S bar (void);
> void quux (S, S);
> void foo (void)
> {
>   quux (bar(), bar());
> }

Not really.  It passed testing for C and C++ at least.  For the above we get
the still bad (-Os to not inline the memcpys)

foo:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %esi
        pushl   %ebx
        subl    $2000, %esp
        leal    -2008(%ebp), %ebx
        pushl   %ebx
        call    bar
        leal    -1008(%ebp), %esi
        pushl   %esi
        call    bar
        subl    $1000, %esp
        movl    %esp, %eax
        pushl   $1000
        pushl   %ebx
        pushl   %eax
        call    memcpy
        subl    $988, %esp
        movl    %esp, %eax
        pushl   $1000
        pushl   %esi
        pushl   %eax
        call    memcpy
        addl    $12, %esp
        call    quux
        addl    $2000, %esp
        leal    -8(%ebp), %esp
        popl    %ebx
        popl    %esi
        popl    %ebp
        ret

which is the same as without the patch.

Richard.



More information about the Gcc-patches mailing list