re PR tree-optimization/90356 (Missed optimization for variables initialized to 0.0)
authorJakub Jelinek <jakub@redhat.com>
Wed, 8 May 2019 07:21:48 +0000 (09:21 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 8 May 2019 07:21:48 +0000 (09:21 +0200)
PR tree-optimization/90356
* match.pd ((X +/- 0.0) +/- 0.0): Optimize into X +/- 0.0 if possible.

* gcc.dg/tree-ssa/pr90356-1.c: New test.
* gcc.dg/tree-ssa/pr90356-2.c: New test.
* gcc.dg/tree-ssa/pr90356-3.c: New test.
* gcc.dg/tree-ssa/pr90356-4.c: New test.

From-SVN: r271001

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c [new file with mode: 0644]

index 4a98ec84c7b9e318b3fd73d1501caa900a8e759e..90354983a74eda6c51849f1c21a941917484eeb9 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/90356
+       * match.pd ((X +/- 0.0) +/- 0.0): Optimize into X +/- 0.0 if possible.
+
 2019-05-07  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/rs6000/rs6000-protos.h (rs6000_legitimize_reload_address_ptr):
index 5e4a4dc51a2b7e3eda0d31bf692d1e6358507166..29c94e01f7d6c973e96492b770a79b19d133a171 100644 (file)
@@ -152,6 +152,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (if (fold_real_zero_addition_p (type, @1, 1))
   (non_lvalue @0)))
 
+/* Even if the fold_real_zero_addition_p can't simplify X + 0.0
+   into X, we can optimize (X + 0.0) + 0.0 or (X + 0.0) - 0.0
+   or (X - 0.0) + 0.0 into X + 0.0 and (X - 0.0) - 0.0 into X - 0.0
+   if not -frounding-math.  For sNaNs the first operation would raise
+   exceptions but turn the result into qNan, so the second operation
+   would not raise it.   */
+(for inner_op (plus minus)
+ (for outer_op (plus minus)
+  (simplify
+   (outer_op (inner_op@3 @0 REAL_CST@1) REAL_CST@2)
+    (if (real_zerop (@1)
+        && real_zerop (@2)
+        && !HONOR_SIGN_DEPENDENT_ROUNDING (type))
+     (with { bool inner_plus = ((inner_op == PLUS_EXPR)
+                               ^ REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@1)));
+            bool outer_plus
+              = ((outer_op == PLUS_EXPR)
+                 ^ REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@2))); }
+      (if (outer_plus && !inner_plus)
+       (outer_op @0 @2)
+       @3))))))
+
 /* Simplify x - x.
    This is unsafe for certain floats even in non-IEEE formats.
    In IEEE, it is unsafe because it does wrong for NaNs.
index e132b5b8d7f3de2eb8ba74e972c2d12774823471..363518ee64eb91ba2c11a0c50786615dfb932abd 100644 (file)
@@ -1,3 +1,11 @@
+2019-05-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/90356
+       * gcc.dg/tree-ssa/pr90356-1.c: New test.
+       * gcc.dg/tree-ssa/pr90356-2.c: New test.
+       * gcc.dg/tree-ssa/pr90356-3.c: New test.
+       * gcc.dg/tree-ssa/pr90356-4.c: New test.
+
 2019-05-07  Cherry Zhang  <cherryyz@google.com>
 
        * go.dg/arrayclear.go: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c
new file mode 100644 (file)
index 0000000..c3a15ea
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/90356 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-rounding-math -fsignaling-nans -fsigned-zeros -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "x_\[0-9]*.D. \\+ 0.0;" 12 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "y_\[0-9]*.D. - 0.0;" 4 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \[+-] 0.0;" 16 "optimized" } } */
+
+double f1 (double x) { return (x + 0.0) + 0.0; }
+double f2 (double y) { return (y + (-0.0)) + (-0.0); }
+double f3 (double y) { return (y - 0.0) - 0.0; }
+double f4 (double x) { return (x - (-0.0)) - (-0.0); }
+double f5 (double x) { return (x + 0.0) - 0.0; }
+double f6 (double x) { return (x + (-0.0)) - (-0.0); }
+double f7 (double x) { return (x - 0.0) + 0.0; }
+double f8 (double x) { return (x - (-0.0)) + (-0.0); }
+double f9 (double x) { double t = x + 0.0; return t + 0.0; }
+double f10 (double y) { double t = y + (-0.0); return t + (-0.0); }
+double f11 (double y) { double t = y - 0.0; return t - 0.0; }
+double f12 (double x) { double t = x - (-0.0); return t - (-0.0); }
+double f13 (double x) { double t = x + 0.0; return t - 0.0; }
+double f14 (double x) { double t = x + (-0.0); return t - (-0.0); }
+double f15 (double x) { double t = x - 0.0; return t + 0.0; }
+double f16 (double x) { double t = x - (-0.0); return t + (-0.0); }
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c
new file mode 100644 (file)
index 0000000..a58c5ac
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR tree-optimization/90356 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-rounding-math -fno-signaling-nans -fsigned-zeros -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times "x_\[0-9]*.D. \\+ 0.0;" 12 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "y_\[0-9]*.D. - 0.0;" 0 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \[+-] 0.0;" 12 "optimized" } } */
+
+#include "pr90356-1.c"
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c
new file mode 100644 (file)
index 0000000..e658130
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR tree-optimization/90356 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -frounding-math -fsignaling-nans -fsigned-zeros -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \[+-] 0.0;" 32 "optimized" } } */
+
+#include "pr90356-1.c"
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c
new file mode 100644 (file)
index 0000000..126cd10
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR tree-optimization/90356 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -frounding-math -fno-signaling-nans -fsigned-zeros -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " \[+-] 0.0;" 32 "optimized" } } */
+
+#include "pr90356-1.c"