DMD backend quality (Was: Re: DIP 1031--Deprecate Brace-Style Struct Initializers--Community Review Round 1 Discussion)
Walter Bright
newshound2 at digitalmars.com
Wed Feb 19 05:42:19 UTC 2020
On 2/18/2020 1:52 PM, H. S. Teoh wrote:
> DMD's inliner, in comparison, balks at the sight of
> things as trivial as writing:
>
> auto myFunc(...) {
> if (cond) return result1;
> return result2;
> }
>
> vs.
>
> auto myFunc(...) {
> if (cond) return result1;
> else return result2;
> }
With:
int fooa(int a, int b, int c) {
if (a)
return b;
return c;
}
int foob(int a, int b, int c) {
if (a)
return b;
else
return c;
}
int test(int a, int b, int c) {
return fooa(a, b, c) + foob(a, b, c);
}
the generated code for test() compiled with -inline -O is:
push EAX
cmp dword ptr 0Ch[ESP],0
je LE
mov EAX,8[ESP]
jmp short L11
LE: mov EAX,[ESP]
L11: add EAX,EAX
pop ECX
ret 8
so it is inlining both forms. If you do have trivial functions that aren't being
inlined, please let me know. Thanks!
More information about the Digitalmars-d
mailing list