[Issue 20189] New: Codegen - functions that call other functions with the same arguments do redundant copying between stack and registers.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 3 02:12:45 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20189
Issue ID: 20189
Summary: Codegen - functions that call other functions with the
same arguments do redundant copying between stack and
registers.
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: elronnd at elronnd.net
Consider this code - contrived, but representative of an actual problem I had:
pragma(inline, false) int second(int a, int b) {
return a+b;
}
pragma(inline, false) int first(int a, int b) {
return second(a, b);
}
It generates this code for first() with dmd version 2.087.1, with optimizations
enabled:
push rbp
mov rbp,rsp
sub rsp,0x10
mov DWORD PTR [rbp-0x10],edi
mov DWORD PTR [rbp-0x8],esi
mov esi,DWORD PTR [rbp-0x8]
mov edi,DWORD PTR [rbp-0x10]
call 3c66c <int perftest.second(int, int)>
mov rsp,rbp
pop rbp
ret
It moves both of its parameters--which are in the edi and esi registers--onto
the stack, and then...back into the registers. Those 4 movs in the middle
could be elided completely.
(As a further optimization, 'return func(...)' could be translated into 'jmp
func', instead of 'call func; ret'--ldc does this.)
--
More information about the Digitalmars-d-bugs
mailing list