On Thursday, 25 August 2016 at 17:22:27 UTC, kinke wrote:
I found it hard to believe LDC generates such crappy code when

Yes that's right, there was an error in my script! What I've posted is actually the asm without -O.

Sure, Foo.foo() and use() could return a constant, but otherwise it can't get much better than this.

The problem here that the example is bad with too agressive optimizations because the CALLs are eliminated despite of no inlining.

Here's a better code to illustrate the idea:

°°°°°°°°°°°°°°°°°°°°°°
interface Foo
{
    int foo() const;
}

int use(const(Foo) foo)
{
    return foo.foo() + foo.foo();
}
°°°°°°°°°°°°°°°°°°°°°°


And I'd expect this asm for a 'const optimization' in use():

push rbp
push rbx
push rax
mov rbx, rdi
mov rax, qword ptr [rbx]
call qword ptr [rax+08h]
add eax, eax // const funct = no side effect, so add the 1st result = save a CALL
add rsp, 08h
pop rbx
pop rbp
ret

Reply via email to