public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4295] Simplify abs (copysign (x, y))
@ 2023-09-27 11:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-09-27 11:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f7d7e26f10e8e329c3521ae7475ed2dfa38ba677

commit r14-4295-gf7d7e26f10e8e329c3521ae7475ed2dfa38ba677
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Sep 27 12:48:50 2023 +0200

    Simplify abs (copysign (x, y))
    
    The following adds simplification of abs (copysign (x, y)) to abs (x).
    
            * match.pd (abs (copysign (x, y)) -> abs (x)): New pattern.
    
            * gcc.dg/fold-abs-6.c: New testcase.

Diff:
---
 gcc/match.pd                      | 5 +++++
 gcc/testsuite/gcc.dg/fold-abs-6.c | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 125083376ad..f0be325be86 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7445,6 +7445,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (COPYSIGN_ALL @0 tree_expr_nonnegative_p@1)
  (abs @0))
 
+(simplify
+ /* fabs (copysign(x, y)) -> fabs (x).  */
+ (abs (COPYSIGN_ALL @0 @1))
+ (abs @0))
+
 (for scale (LDEXP SCALBN SCALBLN)
  /* ldexp(0, x) -> 0.  */
  (simplify
diff --git a/gcc/testsuite/gcc.dg/fold-abs-6.c b/gcc/testsuite/gcc.dg/fold-abs-6.c
new file mode 100644
index 00000000000..42ef9230dfd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/fold-abs-6.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-original" } */
+
+float foo (float x, float y)
+{
+  return __builtin_fabsf (__builtin_copysignf (x, y));
+}
+
+/* { dg-final { scan-tree-dump "return ABS_EXPR <x>;" "original" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-27 11:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-27 11:47 [gcc r14-4295] Simplify abs (copysign (x, y)) 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).