[InstCombine] Fix errno bug in pow expansion to sqrt
authorHubert Tong <hubert.reinterpretcast@gmail.com>
Tue, 22 Sep 2020 22:49:55 +0000 (18:49 -0400)
committerHubert Tong <hubert.reinterpretcast@gmail.com>
Tue, 22 Sep 2020 22:58:05 +0000 (18:58 -0400)
commit32c9991dab5cb1454959561c77f9d0089d981429
tree6d3029c26b7423625df3c67a6f26778521b2e5aa
parentd6ac649ccda289ecc2d2c0cb51892d57e8ec328c
[InstCombine] Fix errno bug in pow expansion to sqrt

A conversion from `pow` to `sqrt` shall not call an `errno`-setting
`sqrt` with -//infinity//: the `sqrt` will set `EDOM` where the `pow`
call need not.

This patch avoids the erroneous (pun not intended) transformation by
applying the restrictions discussed in the thread for
https://lists.llvm.org/pipermail/llvm-dev/2020-September/145051.html.

The existing tests are updated (depending on emphasis in the checks for
library calls, avoidance of overlap, and overall coverage):
  - to add `ninf`, retaining the intended library call,
  - to use the intrinsic, retaining the use of `select`, or
  - to expect the replacement to not occur.

The following is tested:
  - The pow intrinsic folds to a `select` instruction to
    handle -//infinity//.
  - The pow library call folds, with `ninf`, to `sqrt` without the
    `select` instruction associated with handling -//infinity//.
  - The pow library call does not fold to `sqrt` without `ninf`.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D87877
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-1.ll
llvm/test/Transforms/InstCombine/pow-sqrt.ll
llvm/test/Transforms/InstCombine/win-math.ll