diff mbox

[PR16107] Convert cos (-x) into cos (x)

Message ID SN2PR0701MB10242C3820BE33252AB8BE6B8E730@SN2PR0701MB1024.namprd07.prod.outlook.com
State New
Headers show

Commit Message

Hurugalawadi, Naveen Aug. 7, 2015, 8:44 a.m. UTC
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.Hurugalawadi@caviumnetworks.com>

PR middle-end/16107 

	gcc/testsuite/ChangeLog:    		
	* gcc.dg/pr16107.c: New test.  

	gcc/ChangeLog:  
	* match.pd (COS (negate @0) : New simplifier.

Comments

Marc Glisse Aug. 17, 2015, 5:05 a.m. UTC | #1
On Fri, 7 Aug 2015, Hurugalawadi, Naveen wrote:

> 	gcc/ChangeLog:
> 	* match.pd (COS (negate @0) : New simplifier.

Please fix ChangeLog so it is well-parenthesized, the committed version is 
even worse:

> 	* match.pd (div (coss (op @0) : New simplifier.

What is this "div" about?

Thanks,
Hurugalawadi, Naveen Aug. 17, 2015, 5:27 a.m. UTC | #2
Hi Marc Glisse,

Thanks for pointing out the error.

That "div" is not supposed to be there.
Exact pattern is:-
>       * match.pd (coss (op @0) : New simplifier.

However, the exact pattern is present in the sources and a typo has 
been introduced in the ChangeLog.

Sorry for the mistake.

Thanks,
Naveen
diff mbox

Patch

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" } } */