On 12/9/2013 12:05 AM, Jacob Carlborg wrote:
With DMD 2.064.2 produce the exact same assembly code for "foo" and "main" with
our without "pure". I compiled with "dmd -O -release foo.d", am I doing
something wrong?

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.


This is about inherent language opportunities, not whether current
implementations fall short or not.

I think most people will care about what's working right now. Not what could
possibly work sometime in the future.

One cannot do better optimization if the language does not allow it.

Reply via email to