diff options
author | Richard Biener <rguenther@suse.de> | 2016-09-29 12:27:19 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2016-09-29 12:27:19 +0000 |
commit | d657e9952231dee084e1ba658dc3462a82504d78 (patch) | |
tree | 02078d57ea55f712b86706b6e750a6d977ddcd59 | |
parent | 75304c879397bf5179784f004076ce8ef74643a6 (diff) | |
download | gcc-d657e9952231dee084e1ba658dc3462a82504d78.zip gcc-d657e9952231dee084e1ba658dc3462a82504d78.tar.gz gcc-d657e9952231dee084e1ba658dc3462a82504d78.tar.bz2 |
re PR middle-end/55152 (MAX_EXPR(a,-a) is really ABS_EXPR(a))
2016-09-29 Richard Biener <rguenther@suse.de>
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
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/match.pd | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr55152.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/phi-opt-5.c | 2 | ||||
-rw-r--r-- | gcc/tree-ssa-phiopt.c | 2 |
6 files changed, 35 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a5c8e1b..5ebd880 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-09-29 Richard Biener <rguenther@suse.de> + + 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 <james.greenhalgh@arm.com> * defaults.h (TARGET_FLT_EVAL_METHOD_NON_DEFAULT): Remove. diff --git a/gcc/match.pd b/gcc/match.pd index 786cf4c..553e50d 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 6acd1fc..a88a975 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-09-29 Richard Biener <rguenther@suse.de> + + PR middle-end/55152 + * gcc.dg/pr55152.c: New testcase. + * gcc.dg/tree-ssa/phi-opt-5.c: Adjust. + 2016-09-29 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> * 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 0000000..b1a72cb --- /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 37041d7..31c0fc1 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 dd3837d..3f3b88c 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 <gcond *> (last_stmt (cond_bb)); |