public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at tat dot physik dot uni-tuebingen dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/19131] New: alloca returning unnecessarily aligned pointer and uses too much memory
Date: Wed, 22 Dec 2004 14:39:00 -0000	[thread overview]
Message-ID: <20041222143844.19131.rguenth@tat.physik.uni-tuebingen.de> (raw)

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


             reply	other threads:[~2004-12-22 14:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-22 14:39 rguenth at tat dot physik dot uni-tuebingen dot de [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041222143844.19131.rguenth@tat.physik.uni-tuebingen.de \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).