Bugzilla – Bug 275
[llvmgcc] Local array initializers are expanded into large amounts of code
Last modified: 2004-03-09 21:09:47
You need to log in before you can comment on or make changes to this bug.
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
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
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
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