D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6904 - Skip Setting up Stack Frame if No Stack is Used
Summary: Skip Setting up Stack Frame if No Stack is Used
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords: bootcamp, performance
Depends on:
Blocks:
 
Reported: 2011-11-07 10:05 UTC by David Simcha
Modified: 2017-06-25 12:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2011-11-07 10:05:40 UTC
This could affect performance slightly in real-world code if virtual functions are used to return constants in some overrides.

test.d:

int main() {
   return 0;
}

dmd -c -O -inline -release test.d

Disassembly of _Dmain in test.o:

_Dmain  PROC
        push    rbp                                     ; 0000 _ 55
        mov     rbp, rsp                                ; 0001 _ 48: 8B. EC
        xor     eax, eax                                ; 0004 _ 31. C0
        pop     rbp                                     ; 0006 _ 5D
        ret                                             ; 0007 _ C3
_Dmain  ENDP

Do we really need to do the push rbp; mov rbp, rsp; pop rbp when the function doesn't actually use any stack and just sets eax to zero and returns?  GDC elides these extra instructions.  In GDC, compiled with -O1 or higher, _Dmain's body is:

_Dmain  PROC
        xor     eax, eax                                ; 0000 _ 31. C0
        ret                                             ; 0002 _ C3
_Dmain  ENDP
Comment 1 Vladimir Panteleev 2017-06-25 12:14:14 UTC
I believe this was fixed by this pull request:
https://github.com/dlang/dmd/pull/5040