This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Optimize logarithm addition and subtraction
On 08/05/18 20:35, Marc Glisse wrote:
> On Sun, 5 Aug 2018, Bernd Edlinger wrote:
>>> merging log a + log b => log a*b and
>> Maybe a*b could overflow, while adding the logarithms would not?
> Well, that's a discussion that happens every time a new transformation is added to -funsafe-math-optimizations (I assume this one is under that umbrella?). We already may get extra overflow with -fassociative-math for instance. Sure, the overflow (or underflow!) is more likely for log than for addition, but this still seems like the kind of transformation that -ffast-math should enable, in my opinion. Now we can see if I am in the minority...
Yes, this should be unsafe-math
Regarding the second transformation, I think it is invalid.
I tried in sage:
sage: p = x*log(a) + y*log(b)
sage: q = x*y*log(a*b)
sage: print p
6*log(3) + 5*log(2)
sage: print q
sage: print numerical_approx(p)
sage: print numerical_approx(q)