* [PATCH] match.pd: Simplify copysign (x, -x) to -x [PR96715]
@ 2020-08-24 21:39 Jakub Jelinek
2020-08-24 22:58 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-08-24 21:39 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
The following patch implements an optimization suggested in the PR,
copysign(x,-x) can be optimized into -x (even without -ffast-math,
should work fine even for signed zeros and infinities or nans).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2020-08-24 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/96715
* match.pd (copysign(x,-x) -> -x): New simplification.
* gcc.dg/tree-ssa/copy-sign-3.c: New test.
--- gcc/match.pd.jj 2020-08-24 10:00:01.000000000 +0200
+++ gcc/match.pd 2020-08-24 15:53:56.001381109 +0200
@@ -5293,6 +5293,11 @@ (define_operator_list COND_TERNARY
(COPYSIGN_ALL @0 @0)
@0)
+(simplify
+ /* copysign(x,-x) -> -x. */
+ (COPYSIGN_ALL @0 (negate@1 @0))
+ @1)
+
(simplify
/* copysign(x,y) -> fabs(x) if y is nonnegative. */
(COPYSIGN_ALL @0 tree_expr_nonnegative_p@1)
--- gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c.jj 2020-08-24 16:09:11.543453434 +0200
+++ gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c 2020-08-24 16:08:31.360020186 +0200
@@ -0,0 +1,23 @@
+/* PR tree-optimization/96715 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not "= __builtin_copysign" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " = -x_\[0-9]*\\(D\\)" 3 "optimized" } } */
+
+float
+foo (float x)
+{
+ return __builtin_copysignf (x, -x);
+}
+
+double
+bar (double x)
+{
+ return __builtin_copysign (x, -x);
+}
+
+long double
+baz (long double x)
+{
+ return __builtin_copysignl (x, -x);
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] match.pd: Simplify copysign (x, -x) to -x [PR96715]
2020-08-24 21:39 [PATCH] match.pd: Simplify copysign (x, -x) to -x [PR96715] Jakub Jelinek
@ 2020-08-24 22:58 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2020-08-24 22:58 UTC (permalink / raw)
To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches
On Mon, 2020-08-24 at 23:39 +0200, Jakub Jelinek via Gcc-patches wrote:
> Hi!
>
> The following patch implements an optimization suggested in the PR,
> copysign(x,-x) can be optimized into -x (even without -ffast-math,
> should work fine even for signed zeros and infinities or nans).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2020-08-24 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/96715
> * match.pd (copysign(x,-x) -> -x): New simplification.
>
> * gcc.dg/tree-ssa/copy-sign-3.c: New test.
OK
jeff
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-24 22:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 21:39 [PATCH] match.pd: Simplify copysign (x, -x) to -x [PR96715] Jakub Jelinek
2020-08-24 22:58 ` Jeff Law
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).