First Last Prev Next    No search results available
Details
: [llvmgcc] Structure copies result in a LOT of code
Bug#: 233
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.2

:
: code-quality, 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-02-12 11:59
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
------- Comment #1 From Chris Lattner 2004-02-12 11:59:50 -------
LLVM now has an llvm.memcpy intrinsic, so implementing this should be pretty
easy now.

-Chris
------- Comment #2 From Chris Lattner 2004-02-12 12:19:22 -------
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
------- Comment #3 From Chris Lattner 2004-02-12 15:15:38 -------
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

First Last Prev Next    No search results available