First Last Prev Next    No search results available
Details
: [llvmgcc] Local array initializers are expanded into larg...
Bug#: 275
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.2

:
: quality-of-implementation
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2004-03-09 00:02
In the following function, each initializer element is expanded into a
getelementptr/store pair, resulting in a TON of code.  This is a reduced &
simplified testcase from imagemagick, whose giant array is not nearly as
pointless as this one.

----
int test(int x) {
  const int array[] = {
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
     17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 
   };
   return array[x];
} 
----

When the array has more than a few initializers, we should memcpy from a
statically initalized global variable into the array alloca.  Ideally we should
then be able to eliminate the alloca (in this case where the array is never
written to besides the memcpy), but that's an optimization, not a "cannot
compile the testcase because the compiler runs forever" bug.

-Chris
------- Comment #1 From Chris Lattner 2004-03-09 00:54:36 -------
Note to self:  This bug can be fixed in llvm_expand_constructor.  We should
handle the following cases:

* All constant values - Statically initialize a global, and memcpy from it
* Mostly zero values - Initialize with memset, then store nonzero elements into it
* Mostly constant values - Statically initialize a global with the constant
  parts, memcpy from it, then clobber the non-constant parts.

Tommorow.

-Chris
------- Comment #2 From Chris Lattner 2004-03-09 15:48:19 -------
Related to this bug, we currently compile things like this:

int foo() {
  int t[1025] = { 1024 };
}

Into a loop to zero initialize t.  It would be better to use memset when possible.

-Chris
------- Comment #3 From Chris Lattner 2004-03-09 21:09:47 -------
The really bad incarnations of this bug are now fixed.  Patch here:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040308/012934.html

Testcase here:
test/Regression/CFrontend/2004-03-09-LargeArrayInitializers.c

I will file a new bug for the more esoteric bad cases that we still fail, which
are blocked on the rewrite of the CFE initializer code.

-Chris

First Last Prev Next    No search results available