HomePhabricator

Merging r371221 and r371224:

Authored by hansw on Sep 9 2019, 2:43 AM.

Description

Merging r371221 and r371224:


r371221 | spatel | 2019-09-06 18:10:18 +0200 (Fri, 06 Sep 2019) | 3 lines

[SimplifyLibCalls] handle pow(x,-0.0) before it can assert (PR43233)

https://bugs.llvm.org/show_bug.cgi?id=43233


r371224 | jfb | 2019-09-06 18:26:59 +0200 (Fri, 06 Sep 2019) | 39 lines

[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

llvm-svn: 371381

Details

Committed
hanswSep 9 2019, 2:43 AM
Differential Revision
D67248: [InstCombine] pow(x, +/- 0.0) -> 1.0
Parents
rG1c21c1972f92: Merging r371305 and r371307:
Branches
Unknown
Tags
Unknown