Did Walter's pure optimization ever make it into dmd?
ag0aep6g
anonymous at example.com
Mon Apr 2 11:33:29 UTC 2018
On 04/02/2018 10:52 AM, Dennis wrote:
> ```For these examples, I'll use the D programming language compiler that
> is currently under development. (...)
> But what if bar is pure?
>
> pure int bar(int);
>
> int foo(int i)
> {
> return bar(i) + bar(i);
> }
>
> Now the assembler output is:
>
> push EAX ; save argument i on stack
> call bar ; call bar(i)
> add EAX,EAX ; double result
> pop ECX ; clean stack
> ret ; return to caller
>
> bar(i) is called only once```
>
> I've checked whether multiple calls to pure functions get optimized, and
> it seems like they *never* do. I've tried different versions of dmd with
> optimizaiton flags on/off, and also LDC/GDC.
The function also needs the `nothrow` attribute. And you have to compile
with `-O -release`.
https://run.dlang.io/is/GWnUPH
More information about the Digitalmars-d
mailing list