[ConstProp] allow folding for fma that produces NaN
authorSanjay Patel <spatel@rotateright.com>
Thu, 12 Sep 2019 14:10:50 +0000 (14:10 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 12 Sep 2019 14:10:50 +0000 (14:10 +0000)
commit3f5a8083650339336d2431c3376196cdf10e6418
tree26ec92dc6929e8f22e6387929c74e2920288f491
parent03a111dc46456ca6c397a801da0c8f0c22ffc39e
[ConstProp] allow folding for fma that produces NaN

Folding for fma/fmuladd was added here:
rL202914
...and as seen in existing/unchanged tests, that works to propagate NaN
if it's already an input, but we should fold an fma() that creates NaN too.

From IEEE-754-2008 7.2 "Invalid Operation", there are 2 clauses that apply
to fma, so I added tests for those patterns:

  c) fusedMultiplyAdd: fusedMultiplyAdd(0, ∞, c) or fusedMultiplyAdd(∞, 0, c)
     unless c is a quiet NaN; if c is a quiet NaN then it is implementation
     defined whether the invalid operation exception is signaled
  d) addition or subtraction or fusedMultiplyAdd: magnitude subtraction of
     infinities, such as: addition(+∞, −∞)

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

llvm-svn: 371735
llvm/include/llvm/ADT/APFloat.h
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/ConstProp/fma.ll