public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/50938] New: x86 alloca adds 15 twice
@ 2011-10-31 17:37 ian at airs dot com
  2011-10-31 17:44 ` [Bug rtl-optimization/50938] " ppluzhnikov at google dot com
  2011-10-31 20:41 ` ebotcazou at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: ian at airs dot com @ 2011-10-31 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 50938
           Summary: x86 alloca adds 15 twice
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian@airs.com


Using alloca on x86 requires that the return value be aligned to a 16-byte
(boundary).  So code needs to add 15 to the size and then do & ~15.  However,
compile this file:

extern void bar (char *);
void
foo (int n)
{
  bar (__builtin_alloca (n));
}

The generated code adds 30, not 15.  That is, the adjustment is made twice. 
This works but wastes stack space.

The code in allocate_dynamic_stack_space in explow.c has become rather
convoluted and needs to be cleaned up to make this work.  E.g., it does #if
defined (STACK_POINTER_OFFSET), but defaults.h ensures that
STACK_POINTER_OFFSET is always defined.


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

* [Bug rtl-optimization/50938] x86 alloca adds 15 twice
  2011-10-31 17:37 [Bug rtl-optimization/50938] New: x86 alloca adds 15 twice ian at airs dot com
@ 2011-10-31 17:44 ` ppluzhnikov at google dot com
  2011-10-31 20:41 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppluzhnikov at google dot com @ 2011-10-31 17:44 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot
                   |                            |com

--- Comment #1 from Paul Pluzhnikov <ppluzhnikov at google dot com> 2011-10-31 17:43:50 UTC ---
This bug prevent glibc's extend_alloca from working as it is intended.

The macro (for _STACK_GROWS_DOWN) is:

# define extend_alloca(buf, len, newlen) \
  (__typeof (buf)) ({ size_t __newlen = (newlen);                             \
                      char *__newbuf = __alloca (__newlen);                   \
                      if (__newbuf + __newlen == (char *) buf)                \
                        len += __newlen;                                      \
                      else                                                    \
                        len = __newlen;                                       \
                      __newbuf; })

However due to the +30 adjustment, __newbuf + __newlen == (char *) buf is never
true.

This leads to excessive stack use in glibc under some conditions.


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

* [Bug rtl-optimization/50938] x86 alloca adds 15 twice
  2011-10-31 17:37 [Bug rtl-optimization/50938] New: x86 alloca adds 15 twice ian at airs dot com
  2011-10-31 17:44 ` [Bug rtl-optimization/50938] " ppluzhnikov at google dot com
@ 2011-10-31 20:41 ` ebotcazou at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2011-10-31 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-10-31
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org
     Ever Confirmed|0                           |1

--- Comment #2 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-10-31 20:40:55 UTC ---
> The code in allocate_dynamic_stack_space in explow.c has become rather
> convoluted and needs to be cleaned up to make this work.  E.g., it does #if
> defined (STACK_POINTER_OFFSET), but defaults.h ensures that
> STACK_POINTER_OFFSET is always defined.

Yep, this is PR middle-end/47353.


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

end of thread, other threads:[~2011-10-31 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-31 17:37 [Bug rtl-optimization/50938] New: x86 alloca adds 15 twice ian at airs dot com
2011-10-31 17:44 ` [Bug rtl-optimization/50938] " ppluzhnikov at google dot com
2011-10-31 20:41 ` ebotcazou 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).