fixed -ffinite-math-only A-A missing optimisation
authorChristian Bruel <christian.bruel@st.com>
Wed, 22 Aug 2007 14:38:16 +0000 (16:38 +0200)
committerChristian Bruel <chrbr@gcc.gnu.org>
Wed, 22 Aug 2007 14:38:16 +0000 (16:38 +0200)
Co-Authored-By: Richard Guenther <rguenther@suse.de>
From-SVN: r127705

gcc/ChangeLog
gcc/fold-const.c
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-sub.c [new file with mode: 0644]

index f81021ae82c9a352ba741d2ed2fbffa556913384..884552320c08f581dbd5b97c286153f87eb8992a 100644 (file)
@@ -1,3 +1,9 @@
+2007-02-16  Christian Bruel  <christian.bruel@st.com>  
+            Richard Guenther <rguenther@suse.de>
+       
+       * fold-const.c (fold_binary): Optimize A-A if -ffinite-math-only.
+       * simplify_rtx (simplify_binary_operation_1): Likewise.
+               
 2007-08-22  Rask Ingemann Lambertsen  <rask@sygehus.dk>
 
        PR rtl-optimization/32557
index 77187596d2574c069c27c857a0bfa9899a8e3511..ed05f1fc2c0189f82ceabeeed268507d01b2edbc 100644 (file)
@@ -10149,10 +10149,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
         Also note that operand_equal_p is always false if an operand
         is volatile.  */
 
-      if ((! FLOAT_TYPE_P (type)
-          || (flag_unsafe_math_optimizations
-              && !HONOR_NANS (TYPE_MODE (type))
-              && !HONOR_INFINITIES (TYPE_MODE (type))))
+      if ((!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type)))
          && operand_equal_p (arg0, arg1, 0))
        return fold_convert (type, integer_zero_node);
 
index 1acb34c110de14c7db0b8b1aa39e6506e0c10a40..d9cf023c7c2ed5d4d2676a395411987544ff62c1 100644 (file)
@@ -1769,14 +1769,10 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode,
     case MINUS:
       /* We can't assume x-x is 0 even with non-IEEE floating point,
         but since it is zero except in very strange circumstances, we
-        will treat it as zero with -funsafe-math-optimizations and
-        -ffinite-math-only.  */
+        will treat it as zero with -ffinite-math-only.  */
       if (rtx_equal_p (trueop0, trueop1)
          && ! side_effects_p (op0)
-         && (! FLOAT_MODE_P (mode)
-             || (flag_unsafe_math_optimizations
-                 && !HONOR_NANS (mode)
-                 && !HONOR_INFINITIES (mode))))
+         && (!FLOAT_MODE_P (mode) || !HONOR_NANS (mode)))
        return CONST0_RTX (mode);
 
       /* Change subtraction from zero into negation.  (0 - x) is the
index 02cc97c3e15e21cc40c4673b5c9ee42ad96785d6..6068fa9db9ba27313826d318d41698c9e62b7d15 100644 (file)
@@ -1,3 +1,7 @@
+2007-08-21  Christian Bruel  <christian.bruel@st.com>
+
+       * gcc.dg/fold-sub.c: New test.
+       
 2007-08-22  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc.dg/20000724-1.c, gcc.dg/980312-1.c, gcc.dg/980313-1.c,
diff --git a/gcc/testsuite/gcc.dg/fold-sub.c b/gcc/testsuite/gcc.dg/fold-sub.c
new file mode 100644 (file)
index 0000000..28a8dd5
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-ffinite-math-only -fdump-tree-gimple" } */
+
+float f(float x)
+{
+  return x - x;
+}
+
+/* Substraction should be turned into 0.  */
+
+/* { dg-final { scan-tree-dump-not " - " "gimple" } } */
+/* { dg-final { cleanup-tree-dump "gimple" } } */