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
This commit is contained in:
Jakub Jelinek 2019-05-08 09:21:48 +02:00 committed by Jakub Jelinek
parent b65b77cc80
commit f7b7e5d047
7 changed files with 78 additions and 0 deletions

View 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):

View 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.

View 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.

View file

@ -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); }

View file

@ -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"

View file

@ -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"

View file

@ -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"