From: Richard Biener Date: Wed, 5 Oct 2016 11:34:58 +0000 (+0000) Subject: match.pd (copysign(x, CST) -> [-]abs (x)): New pattern. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eeb57981e2d639f144ee6264fdc2bf6f23f8508b;p=gcc.git match.pd (copysign(x, CST) -> [-]abs (x)): New pattern. 2016-10-05 Richard Biener * match.pd (copysign(x, CST) -> [-]abs (x)): New pattern. * gcc.dg/fold-copysign-1.c: New testcase. From-SVN: r240775 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8976e3bfa6..0fd86c50900 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2016-10-05 Richard Biener + + * match.pd (copysign(x, CST) -> [-]abs (x)): New pattern. + 2016-10-05 Richard Biener PR middle-end/77842 diff --git a/gcc/match.pd b/gcc/match.pd index 067e66788cf..e4b5d4d7556 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -452,6 +452,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (hypots @0 (copysigns @1 @2)) (hypots @0 @1))) +/* copysign(x, CST) -> [-]abs (x). */ +(for copysigns (COPYSIGN) + (simplify + (copysigns @0 REAL_CST@1) + (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1))) + (negate (abs @0)) + (abs @0)))) + /* copysign(copysign(x, y), z) -> copysign(x, z). */ (for copysigns (COPYSIGN) (simplify diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d19a7cde3a2..818e5a4be23 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-05 Richard Biener + + * gcc.dg/fold-copysign-1.c: New testcase. + 2016-10-05 Andreas Schwab * g++.dg/pr49847-2.C: Remove. diff --git a/gcc/testsuite/gcc.dg/fold-copysign-1.c b/gcc/testsuite/gcc.dg/fold-copysign-1.c new file mode 100644 index 00000000000..f17d65c24ee --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-copysign-1.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +double foo (double x) +{ + double one = 1.; + return __builtin_copysign (x, one); +} +double bar (double x) +{ + double minuszero = -0.; + return __builtin_copysign (x, minuszero); +} + +/* { dg-final { scan-tree-dump-times "= -" 1 "cddce1" } } */ +/* { dg-final { scan-tree-dump-times "= ABS_EXPR" 2 "cddce1" } } */