Optimisation possibilities: current, future and enhancements

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 25 11:15:47 PDT 2016


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



More information about the Digitalmars-d mailing list