Bugzilla – Bug 233
[llvmgcc] Structure copies result in a LOT of code
Last modified: 2004-02-12 15:15:38
You need to log in before you can comment on or make changes to this bug.
llvmgcc happily code generates structure copies to copy over each element of the structure at a time. Unfortunately, this can result in a LOT of code. This bug turns the "dumpcore" function in Spec95's m88ksim into a gigantic monstrosity that make the optimizers weak in the knees. This should be fixed by emitting a call to 'memcpy' if possible. -Chris
LLVM now has an llvm.memcpy intrinsic, so implementing this should be pretty easy now. -Chris
Here's a testcase: --- struct X { int V[10000]; }; struct X Global1, Global2; void test() { Global2 = Global1; } --- Incidentally, the same testcase shows the desire for fixing Bug 205. :) -Chris
Fixed. Patch here: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040209/011557.html Here's the testcase: test/Regression/CFrontend/2004-02-12-LargeAggregateCopy.c.tr For this test: ---- struct X { int V[10000]; }; struct X Global1, Global2; void test() { memcpy(&Global1, &Global2, sizeof(Global2)); Global2 = Global1; } ---- We now generate the following X86 code, which is substantially better than GCC: $ llvmgcc test2.c -c -o - | llc -regalloc=linearscan .intel_syntax .text .align 16 .globl test .type test, @function test: .LBB0: # entry sub %ESP, 12 mov DWORD PTR [%ESP + 8], %ESI mov DWORD PTR [%ESP + 4], %EDI mov %ECX, 40000 mov %EDI, OFFSET Global1 mov %ESI, OFFSET Global2 rep movsb mov %ECX, 10000 mov %EDI, OFFSET Global2 mov %ESI, OFFSET Global1 rep movsd # FP_REG_KILL mov %EDI, DWORD PTR [%ESP + 4] mov %ESI, DWORD PTR [%ESP + 8] add %ESP, 12 ret .data .comm Global1,40000,4 # %struct.X* %Global1 .comm Global2,40000,4 # %struct.X* %Global2 -Chris