[PATCH] D16696: InstCombine: fabs(x) * fabs(x) -> x * x

Amaury SECHET via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 13:46:55 PST 2016


deadalnix added a subscriber: deadalnix.

================
Comment at: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:621
@@ -620,1 +620,3 @@
 
+      // fabs(X) * fabs(X) -> X * X
+      if (II->getIntrinsicID() == Intrinsic::fabs) {
----------------
DavidKreitzer wrote:
> arsenm wrote:
> > I'm pretty sure this is always safe
> If X is -NaN, this transform will change the result of fabs(X) * fabs(X) from +NaN to -NaN. (In all other cases, it will produce the same result.)
> 
> So my recommendation is to guard this transformation by I.hasNoNaNs().
> 
My understanding of the standard is that NaN has a sign in order to avoid special casing it for operation like fabs. There is no expectation that it has a well defined value.


http://reviews.llvm.org/D16696





More information about the llvm-commits mailing list