Oops, X+0.0 isn't foldable, but X+-0.0 is.
authorChris Lattner <sabre@nondot.org>
Mon, 17 Oct 2005 17:56:38 +0000 (17:56 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 17 Oct 2005 17:56:38 +0000 (17:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23772 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 67a54018c37ed8dabf6173df6197e8005c12f892..d92e126b080c8e15ed3b53ae02853f283ca9bc95 100644 (file)
@@ -694,11 +694,12 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
       return ReplaceInstUsesWith(I, RHS);
 
     // X + 0 --> X
-    // NOTE: -0 + +0 = +0 in non-default rounding modes.  When we support them
-    // we must disable this.  Note that 0.0-0.0 = -0.0, so this doesn't hold
-    // for SUB.
-    if (RHSC->isNullValue())
+    if (!I.getType()->isFloatingPoint()) { // NOTE: -0 + +0 = +0.
+      if (RHSC->isNullValue())
+        return ReplaceInstUsesWith(I, LHS);
+    } else if (cast<ConstantFP>(RHSC)->isExactlyValue(-0.0)) {
       return ReplaceInstUsesWith(I, LHS);
+    }
 
     // X + (signbit) --> X ^ signbit
     if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) {