This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyLibCalls] Support pow(x, -0.5) in replacePowWithSqrt without NSZ/noInfs.
AbandonedPublic

Authored by fhahn on Aug 17 2018, 7:37 AM.

Details

Summary

This patch enables the following expansion in replacePowWithSqrt:

pow(x, -0.5) to (x == -infinity ? +0.0 : fabs(1/sqrt(x)))

I am not entirely sure about handling x == +-0.0, as it seems like different
implementations treat it differently. E.g. on Linux

If x is +0 or -0, and y is less than 0 and not an odd integer, a pole error
occurs and +HUGE_VAL, +HUGE_VALF, or +HUGE_VALL, is returned.

On MacOS

pow(+-0, y) returns +infinity and raises the "divide-by-zero" floating-point
exception for y < 0 and not an odd integer.

So on MacOS we should do the right thing and return +infinity for both
+0 and -0, but on Linux we should actually return +HUGE_VAL.

Diff Detail

Event Timeline

fhahn created this revision.Aug 17 2018, 7:37 AM

There is this nugget from the C documentation:

HUGE_VALF, HUGE_VAL, HUGE_VALL: On implementations that support floating-point infinities, these macros always expand to the positive infinities of float, double, and long double, respectively.

Can you please rebase it, for D50036 touched the same function?

lib/Transforms/Utils/SimplifyLibCalls.cpp
1228

This one and the line below could be shared with the else clause.

fhahn added a comment.Aug 17 2018, 2:09 PM

Can you please rebase it, for D50036 touched the same function?

Will do, thanks!

We were also thinking about expanding pow(x, n+0.5) -> x * x * x * ... * sqrt(x). Is this something you have also planned on adding?

We were also thinking about expanding pow(x, n+0.5) -> x * x * x * ... * sqrt(x). Is this something you have also planned on adding?

No, I don't think that we'll repeat ourselves on this one. LOL Go ahead.

fhahn abandoned this revision.Aug 21 2018, 4:08 AM

Looks like we do not need this after D50036, because 1/+inf gets folded to +0.