From d202f9bdb49ef0b5d778a254796c64a710223515 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 17 Aug 2015 04:47:45 +0000 Subject: [PATCH] re PR tree-optimization/16107 (missed optimization with some math function builtins) 2015-08-17 Richard Biener Naveen H.S PR middle-end/16107 * match.pd (div (coss (op @0) : New simplifier. Co-Authored-By: Naveen H.S From-SVN: r226934 --- gcc/ChangeLog | 6 ++++++ gcc/match.pd | 9 +++++++++ gcc/testsuite/gcc.dg/pr16107.c | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr16107.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a0f656faae5..20b87d7cae9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-08-17 Richard Biener + Naveen H.S + + PR middle-end/16107 + * match.pd (div (coss (op @0) : New simplifier. + 2015-08-14 Alexandre Oliva PR rtl-optimization/64164 diff --git a/gcc/match.pd b/gcc/match.pd index 42b9951c122..71f4127e300 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -55,6 +55,8 @@ along with GCC; see the file COPYING3. If not see (define_operator_list POW10 BUILT_IN_POW10F BUILT_IN_POW10 BUILT_IN_POW10L) (define_operator_list SQRT BUILT_IN_SQRTF BUILT_IN_SQRT BUILT_IN_SQRTL) (define_operator_list CBRT BUILT_IN_CBRTF BUILT_IN_CBRT BUILT_IN_CBRTL) +(define_operator_list COS BUILT_IN_COS BUILT_IN_COSL BUILT_IN_COSF) +(define_operator_list COSH BUILT_IN_COSH BUILT_IN_COSHL BUILT_IN_COSHF) /* Simplifications of operations with one constant operand and @@ -304,6 +306,13 @@ along with GCC; see the file COPYING3. If not see && TYPE_OVERFLOW_UNDEFINED (type)) @0))) +/* Simplify cos (-x) -> cos (x). */ +(for op (negate abs) +(for coss (COS COSH) + (simplify + (coss (op @0)) + (coss @0)))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify diff --git a/gcc/testsuite/gcc.dg/pr16107.c b/gcc/testsuite/gcc.dg/pr16107.c new file mode 100644 index 00000000000..a54d9e19021 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr16107.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +#include + +double t (double x) +{ + x = -x; + x = cos (x); + x = -x; + x = cosh (x); + return x; +} + +/* { dg-final { scan-tree-dump-not "-x" "optimized" } } */ + -- 2.30.2