public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory
@ 2004-12-22 14:39 rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-22 15:06 ` [Bug target/19131] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: rguenth at tat dot physik dot uni-tuebingen dot de @ 2004-12-22 14:39 UTC (permalink / raw)
  To: gcc-bugs

The testcase

int foo(int bar)
{
        int i, res = 0;
        for (i=0; i<bar; ++i) {
                int *x = __builtin_alloca(4);
                res += *x;
        }
        return res;
}

uses a lot more memory than necessary because of __builtin_alloca
apparently returning 16-byte aligned stack space (-O2 -fomit-frame-pointer):

.L5:
        subl    $32, %esp       #,
        incl    %edx    # i
        leal    15(%esp), %eax  #, tmp64
        andl    $-16, %eax      #, tmp64
        addl    (%eax), %ecx    #, res
        cmpl    %edx, %ebx      # i, bar
        jg      .L5     #,

I cannot find anything in the C standard about alloca, but alignment
bigger than the requested storage size should be not needed (though
this may be architecture dependent).

At least playing with alignment should be moved outside of the loop,
so we could save half of the wasted memory (I know the testcase is
dumb, but it's at least simple).

Btw. the same problem applies to 3.4, 3.3 doesn't play alignment
games but still allocates 16 bytes each time (that won't be aligned
to 16 bytes this way anyway?).  2.95 beats all of them again in
simplicity:

.L6:
        addl $-16,%esp
        addl (%esp),%eax
        decl %edx
        jnz .L6

-- 
           Summary: alloca returning unnecessarily aligned pointer and uses
                    too much memory
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rguenth at tat dot physik dot uni-tuebingen dot de
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug target/19131] alloca returning unnecessarily aligned pointer and uses too much memory
  2004-12-22 14:39 [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory rguenth at tat dot physik dot uni-tuebingen dot de
@ 2004-12-22 15:06 ` pinskia at gcc dot gnu dot org
  2004-12-22 18:16 ` rguenth at tat dot physik dot uni-tuebingen dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-12-22 15:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 15:06 -------
The reason you cannot find anything in the C standard is because this is ABI thing so this is invalid

We need to keep the stack aligned sorry.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
          Component|tree-optimization           |target
         Resolution|                            |INVALID


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


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

* [Bug target/19131] alloca returning unnecessarily aligned pointer and uses too much memory
  2004-12-22 14:39 [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-22 15:06 ` [Bug target/19131] " pinskia at gcc dot gnu dot org
@ 2004-12-22 18:16 ` rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-23 22:23 ` rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-23 22:27 ` hubicka at ucw dot cz
  3 siblings, 0 replies; 6+ messages in thread
From: rguenth at tat dot physik dot uni-tuebingen dot de @ 2004-12-22 18:16 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de  2004-12-22 18:16 -------
Subject: Re:  alloca returning unnecessarily aligned pointer
 and uses too much memory

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 15:06 -------
> The reason you cannot find anything in the C standard is because this is ABI thing so this is invalid
> 
> We need to keep the stack aligned sorry.

Inside a function!?  Or just at function callsites?  Humm, the Intel 
compiler produces

..B1.3:                         # Preds ..B1.2 ..B1.4
         movl      $4, %eax                                      #5.12
         subl      %eax, %esp                                    #5.12
         andl      $-16, %esp                                    #5.12
         movl      %esp, %eax                                    #5.12
                                 # LOE eax ebx ebp esi edi
..B1.4:                         # Preds ..B1.3
         addl      (%eax), %ebx                                  #6.3
         addl      $1, %esi                                      #4.21
         cmpl      %edi, %esi                                    #4.2
         jl        ..B1.3

which looks like it aligns the stack after alloca, but it manages to
waste less space by subtracting $4, not $32.

Also if the ABI says the stack is aligned, why do we not make use of 
this and avoid the andl $-16, %esp -- or is the alignment only about
alloca?

I'm a bit confused.

Richard.


-- 


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


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

* [Bug target/19131] alloca returning unnecessarily aligned pointer and uses too much memory
  2004-12-22 14:39 [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-22 15:06 ` [Bug target/19131] " pinskia at gcc dot gnu dot org
  2004-12-22 18:16 ` rguenth at tat dot physik dot uni-tuebingen dot de
@ 2004-12-23 22:23 ` rguenth at tat dot physik dot uni-tuebingen dot de
  2004-12-23 22:27   ` Jan Hubicka
  2004-12-23 22:27 ` hubicka at ucw dot cz
  3 siblings, 1 reply; 6+ messages in thread
From: rguenth at tat dot physik dot uni-tuebingen dot de @ 2004-12-23 22:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de  2004-12-23 22:23 -------
Subject: Re:  alloca returning unnecessarily aligned pointer
 and uses too much memory

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 15:06 -------
> The reason you cannot find anything in the C standard is because this is ABI thing so this is invalid

Where is the ABI specified?  Is it the "System V ABI, Intel386 
Architecture Processor Supplement" document I found at
http://www.caldera.com/developers/devspecs/abi386-4.pdf?
This one talks about word-alignment of the stack, not 16 byte alignment.

> We need to keep the stack aligned sorry.


-- 


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


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

* [Bug target/19131] alloca returning unnecessarily aligned pointer and uses too much memory
  2004-12-22 14:39 [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory rguenth at tat dot physik dot uni-tuebingen dot de
                   ` (2 preceding siblings ...)
  2004-12-23 22:23 ` rguenth at tat dot physik dot uni-tuebingen dot de
@ 2004-12-23 22:27 ` hubicka at ucw dot cz
  3 siblings, 0 replies; 6+ messages in thread
From: hubicka at ucw dot cz @ 2004-12-23 22:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From hubicka at ucw dot cz  2004-12-23 22:27 -------
Subject: Re:  alloca returning unnecessarily aligned pointer and uses too much memory

> 
> ------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de  2004-12-23 22:23 -------
> Subject: Re:  alloca returning unnecessarily aligned pointer
>  and uses too much memory
> 
> pinskia at gcc dot gnu dot org wrote:
> > ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 15:06 -------
> > The reason you cannot find anything in the C standard is because this is ABI thing so this is invalid
> 
> Where is the ABI specified?  Is it the "System V ABI, Intel386 
> Architecture Processor Supplement" document I found at
> http://www.caldera.com/developers/devspecs/abi386-4.pdf?
> This one talks about word-alignment of the stack, not 16 byte alignment.

We keep the stack 16 byte aligned as an extension to support SSE....
Honza
> 
> > We need to keep the stack aligned sorry.
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19131


-- 


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


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

* Re: [Bug target/19131] alloca returning unnecessarily aligned pointer and uses too much memory
  2004-12-23 22:23 ` rguenth at tat dot physik dot uni-tuebingen dot de
@ 2004-12-23 22:27   ` Jan Hubicka
  0 siblings, 0 replies; 6+ messages in thread
From: Jan Hubicka @ 2004-12-23 22:27 UTC (permalink / raw)
  To: rguenth at tat dot physik dot uni-tuebingen dot de; +Cc: gcc-bugs

> 
> ------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de  2004-12-23 22:23 -------
> Subject: Re:  alloca returning unnecessarily aligned pointer
>  and uses too much memory
> 
> pinskia at gcc dot gnu dot org wrote:
> > ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-12-22 15:06 -------
> > The reason you cannot find anything in the C standard is because this is ABI thing so this is invalid
> 
> Where is the ABI specified?  Is it the "System V ABI, Intel386 
> Architecture Processor Supplement" document I found at
> http://www.caldera.com/developers/devspecs/abi386-4.pdf?
> This one talks about word-alignment of the stack, not 16 byte alignment.

We keep the stack 16 byte aligned as an extension to support SSE....
Honza
> 
> > We need to keep the stack aligned sorry.
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19131


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

end of thread, other threads:[~2004-12-23 22:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-22 14:39 [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory rguenth at tat dot physik dot uni-tuebingen dot de
2004-12-22 15:06 ` [Bug target/19131] " pinskia at gcc dot gnu dot org
2004-12-22 18:16 ` rguenth at tat dot physik dot uni-tuebingen dot de
2004-12-23 22:23 ` rguenth at tat dot physik dot uni-tuebingen dot de
2004-12-23 22:27   ` Jan Hubicka
2004-12-23 22:27 ` hubicka at ucw dot cz

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).