Inherent code performance advantages of D over C?

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Dec 9 10:50:30 PST 2013


On Mon, Dec 09, 2013 at 12:45:37AM -0800, Walter Bright wrote:
[...]
> Try this:
> 
>   pure int foo (int a, int b) nothrow {
>     return a + b;
>   }
> 
>   int test() {
>     return foo(1, 2) + foo(1, 2);
>   }
> 
> Compile with:
> 
>   dmd foo -O -release -c
> 
> And dump the assembly:
> 
>             push    EAX
>             mov     EAX,2
>             push    1
>             call    near ptr _D3foo3fooFNaNbiiZi
>             add     EAX,EAX
>             pop     ECX
>             ret
> 
> Granted, more cases can be done, but it *does* take advantage of
> purity here and there.
[...]

Does this currently only happen inside a single expression? Any plans to
have the optimizer recognize pure calls in separate (but identical)
expressions? Jacob's example seems like it *should* be easily detected:

	int a = pureFunc(a,b,c);
	int b = pureFunc(a,b,c); // should elide this second call


T

-- 
The only difference between male factor and malefactor is just a little emptiness inside.


More information about the Digitalmars-d mailing list