re PR tree-optimization/16107 (missed optimization with some math function builtins)
authorRichard Biener <rguenther@suse.de>
Mon, 17 Aug 2015 04:47:45 +0000 (04:47 +0000)
committerNaveen H.S <naveenh@gcc.gnu.org>
Mon, 17 Aug 2015 04:47:45 +0000 (04:47 +0000)
2015-08-17  Richard Biener  <rguenther@suse.de>
    Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>

PR middle-end/16107
* match.pd (div (coss (op @0) : New simplifier.

Co-Authored-By: Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
From-SVN: r226934

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/gcc.dg/pr16107.c [new file with mode: 0644]

index a0f656faae53acd5d6eacf809411ee2152f58aba..20b87d7cae96e3732cb27852128e8a34ea85a319 100644 (file)
@@ -1,3 +1,9 @@
+2015-08-17  Richard Biener  <rguenther@suse.de>
+           Naveen H.S  <Naveen.Hurugalawadi@caviumnetworks.com>
+
+       PR middle-end/16107
+       * match.pd (div (coss (op @0) : New simplifier.
+
 2015-08-14  Alexandre Oliva <aoliva@redhat.com>
 
        PR rtl-optimization/64164
index 42b9951c12214cd713cff2559a37ed5f067e2417..71f4127e300c0980488db180195b20310c79373d 100644 (file)
@@ -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 (file)
index 0000000..a54d9e1
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include <math.h>
+
+double t (double x)
+{
+ x = -x;
+ x = cos (x);
+ x = -x;
+ x = cosh (x);
+ return x;
+}
+
+/* { dg-final { scan-tree-dump-not "-x" "optimized" } } */
+