This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch to bug #86829
On 08/21/2018 02:02 AM, Richard Biener wrote:
> On Mon, Aug 20, 2018 at 9:40 PM Jeff Law <law@redhat.com> wrote:
>>
>> On 08/04/2018 07:22 AM, Giuliano Augusto Faulin Belinassi wrote:
>>> Closes bug #86829
>>>
>>> Description: Adds substitution rules for both sin(atan(x)) and
>>> cos(atan(x)). These formulas are replaced by x / sqrt(x*x + 1) and 1 /
>>> sqrt(x*x + 1) respectively, providing up to 10x speedup. This identity
>>> can be proved mathematically.
>>>
>>> Changelog:
>>>
>>> 2018-08-03 Giuliano Belinassi <giuliano.belinassi@usp.br>
>>>
>>> * match.pd: add simplification rules to sin(atan(x)) and cos(atan(x)).
>>>
>>> Bootstrap and Testing:
>>> There were no unexpected failures in a proper testing in GCC 8.1.0
>>> under a x86_64 running Ubuntu 18.04.
>> I understand these are mathematical identities. But floating point
>> arthmetic in a compiler isn't nearly that clean :-) We have to worry
>> about overflows, underflows, rounding, and the simple fact that many
>> floating point numbers can't be exactly represented.
>>
>> Just as an example, compare the results for
>> x = 0x1.fffffffffffffp1023
>>
>> I think sin(atan (x)) is well defined in that case. But the x*x isn't
>> because it overflows.
>>
>> So I think this has to be somewhere under the -ffast-math umbrella.
>> And the testing requirements for that are painful -- you have to verify
>> it doesn't break the spec benchmark.
>>
>> I know Richi acked in the PR, but that might have been premature.
>
> It's under the flag_unsafe_math_optimizations umbrella, but sure,
> a "proper" way to optimize this would be to further expand
> sqrt (x*x + 1) to fabs(x) + ... (extra terms) that are precise enough
> and not have this overflow issue.
>
> But yes, I do not find (quickly skimming) other simplifications that
> have this kind of overflow issue (in fact I do remember raising
> overflow/underflow issues for other patches).
>
> Thus approval withdrawn.
At least until we can do some testing around spec. There's also a patch
for logarithm addition/subtraction from MCC CS and another from Giuliano
for hyperbolics that need testing with spec. I think that getting that
testing done anytime between now and stage1 close is sufficient -- none
of the 3 patches is particularly complex.
>
> If we had useful range info on floats we might conditionalize such
> transforms appropriately. Or we can enable it on floats and do
> the sqrt (x*x + 1) in double.
Yea. I keep thinking about what it might take to start doing some light
VRP of floating point objects. I'd originally been thinking to just
track 0.0 and exceptional value state. But the more I ponder the more I
think we could use the range information to allow transformations that
are currently guarded by the -ffast-math family of options.
jeff