Optimisation possibilities: current, future and enhancements

Cecil Ward via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 25 11:07:14 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 
> optimizing. These are my results using LDC master on Win64 
> (`ldc2 -O -release -output-s`):
>
> struct Foo
> {
>     immutable _u = 8;
>     int foo() const
>     {
>         return 8 * _u;
>     }
> }
> int use(ref const(Foo) foo)
> {
>     return foo.foo() + foo.foo();
> }
>
> int main()
> {
>     Foo f;
>     return use(f);
> }
>
>
> _D7current3Foo3fooMxFZi:
> 	movl	(%rcx), %eax
> 	shll	$3, %eax
> 	retq
>
> _D7current3useFKxS7current3FooZi:
> 	movl	(%rcx), %eax
> 	shll	$4, %eax
> 	retq
>
> _Dmain:
> 	movl	$128, %eax
> 	retq
>
> Sure, Foo.foo() and use() could return a constant, but 
> otherwise it can't get much better than this.

I think that here the optimisation is only because LDC can “see” 
the text of the method. When expansion is not possible, that 
would be the real test.



More information about the Digitalmars-d mailing list