aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-09-27 12:48:50 +0200
committerRichard Biener <rguenther@suse.de>2023-09-27 13:45:20 +0200
commitf7d7e26f10e8e329c3521ae7475ed2dfa38ba677 (patch)
treecee5158efbdbb37229c13ab13972d8c23dafafd2
parentd326bb6d7588425d013791299272f913fb23e56d (diff)
downloadgcc-f7d7e26f10e8e329c3521ae7475ed2dfa38ba677.zip
gcc-f7d7e26f10e8e329c3521ae7475ed2dfa38ba677.tar.gz
gcc-f7d7e26f10e8e329c3521ae7475ed2dfa38ba677.tar.bz2
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.
-rw-r--r--gcc/match.pd5
-rw-r--r--gcc/testsuite/gcc.dg/fold-abs-6.c9
2 files changed, 14 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 1250833..f0be325 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 0000000..42ef923
--- /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" } } */