]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Simplify abs (copysign (x, y))
authorRichard Biener <rguenther@suse.de>
Wed, 27 Sep 2023 10:48:50 +0000 (12:48 +0200)
committerRichard Biener <rguenther@suse.de>
Wed, 27 Sep 2023 11:45:20 +0000 (13:45 +0200)
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.

gcc/match.pd
gcc/testsuite/gcc.dg/fold-abs-6.c [new file with mode: 0644]

index 125083376ad243a818f1fa48ee58e8de27a8ed98..f0be325be865b2bfdf174027a4bfe75a0f820981 100644 (file)
@@ -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 (file)
index 0000000..42ef923
--- /dev/null
@@ -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" } } */