First Last Prev Next    No search results available
Details
: [x86] wierd stack/frame pointer manipulation
Bug#: 237
: libraries
: Backend: X86
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.2

:
: code-quality
:
:
  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-13 23:46
The X86 backend seems to confuse itself thoroughly when adjusting the stack and
framepointer in several cases, causing inefficient code to be generated.  For
example, this trivial function:

int %test(int %X) {
        ret int %X
}

Generates this code:

test:
        sub %ESP, 4
        mov %EAX, DWORD PTR [%ESP + 8]
        add %ESP, 4
        ret 

Obviously the ESP adjustments are unnecessary.  Things get even wierder when you
turn off frame-pointer elimination.  You get:

test:
        sub %ESP, 4
        mov DWORD PTR [%ESP], %EBP
        lea %EBP, DWORD PTR [%ESP + 4]
        mov %EAX, DWORD PTR [%EBP + 4]
        mov %ESP, %EBP
        mov %EBP, DWORD PTR [%ESP - 4]
        ret 

The strange part of this is that EBP doesn't point to the old EBP value, it
points to the return address!  I think this violates every X86 convention every
invented, and is inefficient (in space and time) to boot.

The X86 backend seems to be consistent in this wierdness at least, so it
compiles programs correctly, but there is no reason for this.

-Chris
------- Comment #1 From Chris Lattner 2004-02-14 18:21:53 -------
This bug is now fixed.  Testcase here:
test/Regression/CodeGen/X86/2004-02-14-InefficientStackPointer.llx

The problem with the no-framepointer case was that the code generator was trying
to keep the stack pointer aligned (a nobel goal), which is unneeded in functions
that do not call other functions.  Patches:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040209/011678.html
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040209/011679.html

The 'have a framepointer' bug was just silly, there was no particular reason for
it.  Here's the patch:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040209/011687.html

-Chris

First Last Prev Next    No search results available