public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-2832] match.pd: Simplify copysign (x, -x) to -x [PR96715]
@ 2020-08-25 5:22 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-08-25 5:22 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:bb5e895245ebef488b63efc239f64488aef65cf1
commit r11-2832-gbb5e895245ebef488b63efc239f64488aef65cf1
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Aug 25 07:21:26 2020 +0200
match.pd: Simplify copysign (x, -x) to -x [PR96715]
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).
2020-08-25 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.
Diff:
---
gcc/match.pd | 5 +++++
gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/gcc/match.pd b/gcc/match.pd
index 2cffcae3d8b..6e45836e32b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -5293,6 +5293,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(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)
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c b/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c
new file mode 100644
index 00000000000..f52e04d2293
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/copy-sign-3.c
@@ -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);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-25 5:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 5:22 [gcc r11-2832] match.pd: Simplify copysign (x, -x) to -x [PR96715] Jakub Jelinek
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).