Hi,
Please find attached the patch "pr16107.patch" that converts the pattern:-
cos (-x) -> cos (x)
Please review and let me know if its okay.
Regression tested on AARH64 and x86_64.
Thanks,
Naveen
2015-08-07 Naveen H.S <naveen.hurugalaw...@caviumnetworks.com>
PR middle-end/16107
gcc/testsuite/ChangeLog:
* gcc.dg/pr16107.c: New test.
gcc/ChangeLog:
* match.pd (COS (negate @0) : New simplifier.
diff --git a/gcc/match.pd b/gcc/match.pd
index 18045b8..a8b5105 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -55,6 +55,7 @@ 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)
/* Simplifications of operations with one constant operand and
@@ -303,6 +304,11 @@ along with GCC; see the file COPYING3. If not see
(if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
@0)))
+/* Simplify cos (-x) -> cos (x). */
+(simplify
+ (COS (negate @0))
+ (COS @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 0000000..b2e509a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr16107.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-require-effective-target int32 } */
+
+#include <math.h>
+
+double t (double x)
+{
+ x = -x;
+ x = cos (x);
+ return x;
+}
+
+/* { dg-final { scan-tree-dump-not "-x" "optimized" } } */