Comment #0 by bearophile_hugs — 2012-12-16T21:04:38Z
void main() {
int x;
int foo() {
return x;
}
int bar() {
return foo();
}
}
DMD 2.061alpha (with -O -release -inline -noboundscheck) gives this asm, showing foo() is not inlined in bar():
main.foo:
push EAX
mov EAX, [EAX]
pop ECX
ret
main.bar:
push EAX
call near ptr _D4test4mainFZv3fooMFZi
pop ECX
ret
main:
push EAX
xor EAX, EAX
mov [ESP], EAX
pop ECX
ret
Comment #1 by hsteoh — 2014-11-13T00:05:56Z
Seems to be fixed in git HEAD; the generated code with `dmd -O -inline -release` is now:
------
000000000041b188 <_Dmain>:
41b188: 55 push %rbp
41b189: 48 8b ec mov %rsp,%rbp
41b18c: 48 83 ec 10 sub $0x10,%rsp
41b190: 31 c0 xor %eax,%eax
41b192: 89 45 f8 mov %eax,-0x8(%rbp)
41b195: 48 8b e5 mov %rbp,%rsp
41b198: 5d pop %rbp
41b199: c3 retq
41b19a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
000000000041b1a0 <_D4test4mainFZ3fooMFZi>:
41b1a0: 55 push %rbp
41b1a1: 48 8b ec mov %rsp,%rbp
41b1a4: 48 83 ec 10 sub $0x10,%rsp
41b1a8: 8b 47 f8 mov -0x8(%rdi),%eax
41b1ab: 48 8b e5 mov %rbp,%rsp
41b1ae: 5d pop %rbp
41b1af: c3 retq
000000000041b1b0 <_D4test4mainFZ3barMFZi>:
41b1b0: 55 push %rbp
41b1b1: 48 8b ec mov %rsp,%rbp
41b1b4: 48 83 ec 10 sub $0x10,%rsp
41b1b8: 8b 47 f8 mov -0x8(%rdi),%eax
41b1bb: 48 8b e5 mov %rbp,%rsp
41b1be: 5d pop %rbp
41b1bf: c3 retq
------
Tested on Linux/64bit. Not sure if Windows might give different results.