[InstCombine] pow(x, +/- 0.0) -> 1.0

Summary:

This isn't an important optimization at all... We're already doing:

pow(x, 0.0) -> 1.0

My patch merely teaches instcombine that -0.0 does the same.

However, doing this fixes an AMAZING bug! Compile this program:

extern "C" double pow(double, double); double boom(double base) { return pow(base, -0.0); }

With:

clang++ ~/Desktop/fast-math.cpp -ffast-math -O2 -S

And clang will crash with a signal. Wow, fast math is so fast it ICEs the

compiler! Arguably, the generated math is infinitely fast.

What's actually happening is that we recurse infinitely in getPow. In debug we

hit its assertion:

assert(Exp != 0 && "Incorrect exponent 0 not handled");

We avoid this entire mess if we instead recognize that an exponent of positive

and negative zero yield 1.0.

A separate commit, r371221, fixed the same problem. This only contains the added

tests.

rdar://problem/54598300

Reviewers: scanon

Subscribers: hiraditya, jkorous, dexonsmith, ributzka, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67248