public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/19805] New: sub-optimal initialisation of array on the stack
@ 2005-02-07 22:03 peter at p12n dot org
  2005-02-08 10:12 ` [Bug middle-end/19805] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: peter at p12n dot org @ 2005-02-07 22:03 UTC (permalink / raw)
  To: gcc-bugs

gcc version 4.0.0 20050110 (experimental) - from Debian 'gcc-snapshot' package. 
[Thread model: posix.  I doubt configure flags are important here.]

gcc produces quite poor code when initialising a stack char[] to an empty string.
 This is at any optimisation level, including -Os.

extern void foo(char *);
void bar(void) { char x[65536] = ""; foo(x); }

(foo() prevents x[] from being optimised away.)

This generates a 64 kB chunk of nulls in .rodata, then proceeds to copy in the
first byte of this region, ignore the other 65535 bytes, and call memset. 
Similar story if I initialise to a non-empty string - an inline memcpy followed
by a memset, and still a huge unneeded block of zeroes.

Simple workaround: initialise the array to {} instead of "".  The generated code
in that case looks much better - just a memset, no .rodata at all.  There's still
the question of why not inline the memset, since the array is known to be nicely
aligned.

(My real code didn't need 65536 bytes of stack - that was just 'reductio ad
absurdum' to demonstrate that gcc doesn't get any smarter as the useless chunk of
.rodata gets larger.)

-- 
           Summary: sub-optimal initialisation of array on the stack
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: peter at p12n dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


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


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

* [Bug middle-end/19805] sub-optimal initialisation of array on the stack
  2005-02-07 22:03 [Bug middle-end/19805] New: sub-optimal initialisation of array on the stack peter at p12n dot org
@ 2005-02-08 10:12 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-08 10:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-07 22:05 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|minor                       |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-07 22:05:55
               date|                            |


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


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

end of thread, other threads:[~2005-02-07 22:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07 22:03 [Bug middle-end/19805] New: sub-optimal initialisation of array on the stack peter at p12n dot org
2005-02-08 10:12 ` [Bug middle-end/19805] " pinskia 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).