From f7b7e5d04712f3672a01d546e0f82328651d0c89 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 8 May 2019 09:21:48 +0200 Subject: [PATCH] re PR tree-optimization/90356 (Missed optimization for variables initialized to 0.0) 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 | 5 +++++ gcc/match.pd | 22 ++++++++++++++++++++++ gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c | 23 +++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c | 8 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c | 6 ++++++ gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c | 6 ++++++ 7 files changed, 78 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4a98ec84c7b..90354983a74 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-05-08 Jakub Jelinek + + PR tree-optimization/90356 + * match.pd ((X +/- 0.0) +/- 0.0): Optimize into X +/- 0.0 if possible. + 2019-05-07 Segher Boessenkool * config/rs6000/rs6000-protos.h (rs6000_legitimize_reload_address_ptr): diff --git a/gcc/match.pd b/gcc/match.pd index 5e4a4dc51a2..29c94e01f7d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -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. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e132b5b8d7f..363518ee64e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2019-05-08 Jakub Jelinek + + 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 * 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 index 00000000000..c3a15ea21af --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-1.c @@ -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 index 00000000000..a58c5aca205 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-2.c @@ -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 index 00000000000..e658130c69f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-3.c @@ -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 index 00000000000..126cd10928b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr90356-4.c @@ -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" -- 2.30.2