ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 262 forks source link

Enhancement: optimize `pure` function calls better #2088

Open JohanEngelen opened 7 years ago

JohanEngelen commented 7 years ago

See https://reviews.llvm.org/rL301680

Would this attribute be helpful for pure functions? Or does it imply too much?

JohanEngelen commented 5 years ago

speculatable would be too much on a pure function: pure in D does not mean calls can be introduced that would otherwise not happen. E.g. calling foo(0) for code fragmentif (x != 0) foo(x).

What we can do is apply readnone or readonly to pure functions that don't take pointer arguments (or only immutable pointers?). https://d.godbolt.org/z/i2Dpxw

kinke commented 5 years ago

We also have lovely stuff like void* pureMalloc()(size_t size) @trusted pure @nogc nothrow (core.memory)...

dnadlinger commented 5 years ago

pure != PUREstrong anyway.