[LLVMbugs] [Bug 4883] New: Codegen/X86-32: missed optimization on first arg passing, unneccessary stack moves

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Fri Sep 4 04:43:36 PDT 2009


http://llvm.org/bugs/show_bug.cgi?id=4883

           Summary: Codegen/X86-32: missed optimization on first arg
                    passing, unneccessary stack moves
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: edwintorok at gmail.com
                CC: llvmbugs at cs.uiuc.edu


For intra-class method calls LLVM generates suboptimal code.

Consider this code:
class A {
    public:
        __attribute__((noinline)) int bar(int b) {
            return b+4;
        }
        __attribute__((noinline)) int foo(int b) {
            return bar(b*4);
        }
        __attribute__((noinline)) int foo() {
            return bar(8);
        }
};
A a;
int main()
{
    return a.foo(4);
}

LLVM-G++ generates this at -O3 for foo:
ZN1A3fooEi:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    12(%ebp), %eax
        shll    $2, %eax
        movl    %eax, 4(%esp)
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        call    _ZN1A3barEi
        addl    $8, %esp
        popl    %ebp
        ret
_ZN1A4foo2Ev:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        movl    $8, 4(%esp)
        call    _ZN1A3barEi
        addl    $8, %esp
        popl    %ebp
        ret
_ZN1A4foo3Eii:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        movl    16(%ebp), %eax
        addl    12(%ebp), %eax
        movl    %eax, 4(%esp)
        movl    8(%ebp), %eax
        movl    %eax, (%esp)
        call    _ZN1A3barEi
        addl    $8, %esp
        popl    %ebp
        ret

G++-4.3 generates this code:
_ZN1A4foo3Eii:
.LFB5:
        pushl   %ebp
.LCFI7:
        movl    %esp, %ebp
.LCFI8:
        movl    16(%ebp), %eax
        addl    %eax, 12(%ebp)
        popl    %ebp
        jmp     _ZN1A3barEi
_ZN1A4foo2Ev:
.LFB4:
        pushl   %ebp
.LCFI4:
        movl    %esp, %ebp
.LCFI5:
        subl    $8, %esp
.LCFI6:
        movl    8(%ebp), %eax
        movl    $8, 4(%esp)
        movl    %eax, (%esp)
        call    _ZN1A3barEi
        leave
        ret
_ZN1A4foo3Eii:
.LFB5:
        pushl   %ebp
.LCFI7:
        movl    %esp, %ebp
.LCFI8:
        movl    16(%ebp), %eax
        addl    %eax, 12(%ebp)
        popl    %ebp
        jmp     _ZN1A3barEi

With LLVM there are a lot of unnecessary stack moves.

This doesn't occur on x86-64 because args are passed in registers.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list