OSDN Git Service

[InstSimplify] fix folds for (0.0 - X) + X --> 0 (PR27151)
authorSanjay Patel <spatel@rotateright.com>
Wed, 14 Mar 2018 21:23:27 +0000 (21:23 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 14 Mar 2018 21:23:27 +0000 (21:23 +0000)
commit2a44ab0eda79ebc30e16123e42336907bbafcae6
tree289bf9e13735ea20ff816d6b4bffa1b883c5ef9b
parent8f10645fe18b672f9c0553845efc73073f573dd9
[InstSimplify] fix folds for (0.0 - X) + X --> 0 (PR27151)

As shown in:
https://bugs.llvm.org/show_bug.cgi?id=27151
...the existing fold could miscompile when X is NaN.

The fold was also dependent on 'ninf' but that's not necessary.

From IEEE-754 (with default rounding which we can assume for these opcodes):
"When the sum of two operands with opposite signs (or the difference of two
operands with like signs) is exactly zero, the sign of that sum (or difference)
shall be +0...However, x + x = x − (−x) retains the same sign as x even when
x is zero."

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327575 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/fast-math.ll