public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR16107] Convert cos (-x)  into cos (x)
@ 2015-08-07  8:44 Hurugalawadi, Naveen
  2015-08-17  5:24 ` Marc Glisse
  0 siblings, 1 reply; 5+ messages in thread
From: Hurugalawadi, Naveen @ 2015-08-07  8:44 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr16107.patch --]
[-- Type: text/x-patch; name="pr16107.patch", Size: 1277 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PR16107] Convert cos (-x)  into cos (x)
  2015-08-07  8:44 [PR16107] Convert cos (-x) into cos (x) Hurugalawadi, Naveen
@ 2015-08-17  5:24 ` Marc Glisse
  2015-08-17  6:44   ` Hurugalawadi, Naveen
  0 siblings, 1 reply; 5+ messages in thread
From: Marc Glisse @ 2015-08-17  5:24 UTC (permalink / raw)
  To: Hurugalawadi, Naveen; +Cc: gcc-patches

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,

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PR16107] Convert cos (-x)  into cos (x)
  2015-08-17  5:24 ` Marc Glisse
@ 2015-08-17  6:44   ` Hurugalawadi, Naveen
  0 siblings, 0 replies; 5+ messages in thread
From: Hurugalawadi, Naveen @ 2015-08-17  6:44 UTC (permalink / raw)
  To: marc.glisse; +Cc: gcc-patches

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
________________________________________
From: Marc Glisse <marc.glisse@inria.fr>
Sent: Monday, August 17, 2015 10:35 AM
To: Hurugalawadi, Naveen
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PR16107] Convert cos (-x)  into cos (x)

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,

--
Marc Glisse

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PR16107] Convert cos (-x) into cos (x)
  2015-08-07  8:55 Uros Bizjak
@ 2015-08-11 12:55 ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2015-08-11 12:55 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Hurugalawadi, Naveen

On Fri, Aug 7, 2015 at 10:55 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> Hello!
>
>> Please find attached the patch "pr16107.patch" that converts the pattern:-cos (-x) -> cos (x)
>> Please review and let me know if its okay.
>
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +/* { dg-require-effective-target int32 } */
>
> There are no integers in the testcase.

Ok with the int32 target removed and also handling abs like

(for op (negate abs)
 (for cos (COS)
   (cos (op @0))
   (cos @0)))

you can also do abs as a followup if you like.  Btw, with this (IMHO)
fold_builtin_cos/cosh can be reduced to constant folding, thus
remove their fold_strip_sign_nops () path.

Thanks,
Richard.

> Uros.
>
> +#include <math.h>
> +
> +double t (double x)
> +{
> + x = -x;
> + x = cos (x);
> + return x;
> +}
> +
> +/* { dg-final { scan-tree-dump-not "-x" "optimized" } } */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PR16107] Convert cos (-x) into cos (x)
@ 2015-08-07  8:55 Uros Bizjak
  2015-08-11 12:55 ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Uros Bizjak @ 2015-08-07  8:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: Hurugalawadi, Naveen

Hello!

> Please find attached the patch "pr16107.patch" that converts the pattern:-cos (-x) -> cos (x)
> Please review and let me know if its okay.

+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-require-effective-target int32 } */

There are no integers in the testcase.

Uros.

+#include <math.h>
+
+double t (double x)
+{
+ x = -x;
+ x = cos (x);
+ return x;
+}
+
+/* { dg-final { scan-tree-dump-not "-x" "optimized" } } */

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-17  5:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-07  8:44 [PR16107] Convert cos (-x) into cos (x) Hurugalawadi, Naveen
2015-08-17  5:24 ` Marc Glisse
2015-08-17  6:44   ` Hurugalawadi, Naveen
2015-08-07  8:55 Uros Bizjak
2015-08-11 12:55 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).