From 54f84ca9c7a1955f9760df4c2df72be9272e0db3 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 5 Oct 2016 07:48:24 +0000 Subject: [PATCH] re PR middle-end/55152 (MAX_EXPR(a,-a) is really ABS_EXPR(a)) 2016-10-05 Richard Biener PR middle-end/55152 * match.pd (min(a,-a) -> -abs(a)): New pattern. * gcc.dg/pr55152-2.c: New testcase. From-SVN: r240770 --- gcc/ChangeLog | 5 +++++ gcc/match.pd | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr55152-2.c | 13 +++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr55152-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ad08f0f771f..a65f491b3ee 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-10-05 Richard Biener + + PR middle-end/55152 + * match.pd (min(a,-a) -> -abs(a)): New pattern. + 2016-10-04 Ian Lance Taylor * explow.c (allocate_dynamic_stack_space): Call diff --git a/gcc/match.pd b/gcc/match.pd index dadf51cd205..067e66788cf 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1291,6 +1291,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (! ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_UNDEFINED (type))) (abs @0))) +/* min(a,-a) -> -abs(a). */ +(simplify + (min:c @0 (negate @0)) + (if (TREE_CODE (type) != COMPLEX_TYPE + && (! ANY_INTEGRAL_TYPE_P (type) + || TYPE_OVERFLOW_UNDEFINED (type))) + (negate (abs @0)))) (simplify (min @0 @1) (switch diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 41186f84162..e77ed889553 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-10-05 Richard Biener + + PR middle-end/55152 + * gcc.dg/pr55152-2.c: New testcase. + 2016-10-04 Jerry DeLisle * gfortran.dg/dtio_15.f90: New test. diff --git a/gcc/testsuite/gcc.dg/pr55152-2.c b/gcc/testsuite/gcc.dg/pr55152-2.c new file mode 100644 index 00000000000..54db0f2062d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr55152-2.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" } } */ -- 2.30.2