From: Richard Biener Date: Thu, 29 Sep 2016 12:27:19 +0000 (+0000) Subject: re PR middle-end/55152 (MAX_EXPR(a,-a) is really ABS_EXPR(a)) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d657e9952231dee084e1ba658dc3462a82504d78;p=gcc.git re PR middle-end/55152 (MAX_EXPR(a,-a) is really ABS_EXPR(a)) 2016-09-29 Richard Biener PR middle-end/55152 * match.pd: Add max(a,-a) -> abs(a) pattern. * tree-ssa-phiopt.c (minmax_replacement): Disable for HONOR_SIGNED_ZEROS types. * gcc.dg/pr55152.c: New testcase. * gcc.dg/tree-ssa/phi-opt-5.c: Adjust. From-SVN: r240615 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a5c8e1bb996..5ebd880f444 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-09-29 Richard Biener + + PR middle-end/55152 + * match.pd: Add max(a,-a) -> abs(a) pattern. + * tree-ssa-phiopt.c (minmax_replacement): Disable for + HONOR_SIGNED_ZEROS types. + 2016-09-29 James Greenhalgh * defaults.h (TARGET_FLT_EVAL_METHOD_NON_DEFAULT): Remove. diff --git a/gcc/match.pd b/gcc/match.pd index 786cf4ce042..553e50d2d03 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1271,6 +1271,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (max:c (min:c @0 @1) @1) @1) +/* max(a,-a) -> abs(a). */ +(simplify + (max:c @0 (negate @0)) + (if (TREE_CODE (type) != COMPLEX_TYPE + && (! ANY_INTEGRAL_TYPE_P (type) + || TYPE_OVERFLOW_UNDEFINED (type))) + (abs @0))) (simplify (min @0 @1) (switch diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6acd1fc255f..a88a975d6a0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-09-29 Richard Biener + + PR middle-end/55152 + * gcc.dg/pr55152.c: New testcase. + * gcc.dg/tree-ssa/phi-opt-5.c: Adjust. + 2016-09-29 Rainer Orth * gcc.dg/profile-update-warning.c: Restrict to ia32. diff --git a/gcc/testsuite/gcc.dg/pr55152.c b/gcc/testsuite/gcc.dg/pr55152.c new file mode 100644 index 00000000000..b1a72cb5a29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr55152.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -ffinite-math-only -fno-signed-zeros -fstrict-overflow -fdump-tree-optimized" } */ + +double g (double a) +{ + return (a>=-a)?a:-a; +} +int f(int a) +{ + return (a>=-a)?a:-a; +} + +/* { dg-final { scan-tree-dump-times "ABS_EXPR" 2 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c index 37041d7dabb..31c0fc1f2fb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -ffinite-math-only -fdump-tree-phiopt1" } */ +/* { dg-options "-O1 -ffinite-math-only -fno-signed-zeros -fdump-tree-phiopt1" } */ float repl1 (float varx) { diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index dd3837d0da1..3f3b88cfc61 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -1075,7 +1075,7 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, type = TREE_TYPE (PHI_RESULT (phi)); /* The optimization may be unsafe due to NaNs. */ - if (HONOR_NANS (type)) + if (HONOR_NANS (type) || HONOR_SIGNED_ZEROS (type)) return false; cond = as_a (last_stmt (cond_bb));