Don wrote:
bearophile wrote:

Isn't sin(x)+sin(x) pure? Even if the compiler doesn't want to replace x+x with x*2 because x is a floating point, it can do:

y = sin(x)
y+y

And that gives the same result even with FPs.

Yes. From further investigation, I've found that:
(1) the optimisation of pure only happens for int returns, not for floating-point return types. It should convert purefunc(x)+purefunc(x) into 2*purefunc(x) if the return type of purefunc is int, float, or complex.

(2) the back-end isn't smart enough to convert f*2 into f+f.
I've fixed (2), patch to the backend is in bigzilla 2888.
I learnt a lot about the backend in the process, maybe I can fix (1) now.

Reply via email to