public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: liuhongt <hongtao.liu@intel.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Hongtao Liu <crazylht@gmail.com>,
	 "H. J. Lu" <hjl.tools@gmail.com>
Subject: Re: [PATCH 1/2] [Middle-end] Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a,b).
Date: Thu, 4 Nov 2021 08:47:08 +0100	[thread overview]
Message-ID: <CAFiYyc1p5pxoc7G5mJVOG9V+eCDZkdhE7ev=VEu5FcKpw8R7Ng@mail.gmail.com> (raw)
In-Reply-To: <20211104064510.93649-1-hongtao.liu@intel.com>

On Thu, Nov 4, 2021 at 7:45 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> a and b are same type as the truncation type and has less precision
> than extend type.
>
> Bootstrapped and regtested on x86-64-pc-linux-gnu{-m32,}.
> Ok for trunk?

OK.

Richard.

> gcc/ChangeLog:
>
>         PR target/102464
>         * match.pd: simplify (trunc)copysign((extend)a, (extend)b) to
>         .COPYSIGN (a,b) when a and b are same type as the truncation
>         type and has less precision than extend type.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.target/i386/pr102464-copysign-1.c: New test.
> ---
>  gcc/match.pd                                  | 13 +++
>  .../gcc.target/i386/pr102464-copysign-1.c     | 80 +++++++++++++++++++
>  2 files changed, 93 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 0734c45700c..f63079023d0 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6169,6 +6169,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>           && direct_internal_fn_supported_p (as_internal_fn (tos),
>                                              type, OPTIMIZE_FOR_BOTH))
>         (tos @0))))
> +
> +/* Simplify (trunc) copysign ((extend)x, (extend)y) to copysignf (x, y),
> +   x,y is float value, similar for _Float16/double.  */
> +(for copysigns (COPYSIGN_ALL)
> + (simplify
> +  (convert (copysigns (convert@2 @0) (convert @1)))
> +   (if (optimize
> +       && types_match (type, TREE_TYPE (@0))
> +       && types_match (type, TREE_TYPE (@1))
> +       && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> +       && direct_internal_fn_supported_p (IFN_COPYSIGN,
> +                                         type, OPTIMIZE_FOR_BOTH))
> +    (IFN_COPYSIGN @0 @1))))
>  #endif
>
>  (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> diff --git a/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c b/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c
> new file mode 100644
> index 00000000000..95a39509738
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102464-copysign-1.c
> @@ -0,0 +1,80 @@
> +/* PR target/102464.  */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ftree-vectorize -mfpmath=sse -fdump-tree-optimized" } */
> +
> +#include<math.h>
> +void foo1 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] = copysignf (b[i], c[i]);
> +}
> +
> +void foo2 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] = copysign (b[i], c[i]);
> +}
> +
> +void foo3 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] = copysignl (b[i], c[i]);
> +}
> +
> +void foo4 (float* __restrict a, float* b, float* c)
> +{
> +  for (int i = 0; i != 4; i++)
> +    a[i] = copysign (b[i], c[i]);
> +}
> +
> +void foo5 (float* __restrict a, float* b, float* c)
> +{
> +  for (int i = 0; i != 4; i++)
> +    a[i] = copysignl (b[i], c[i]);
> +}
> +
> +void foo6 (double* __restrict a, double* b, double* c)
> +{
> +  for (int i = 0; i != 4; i++)
> +    a[i] = copysignl (b[i], c[i]);
> +}
> +
> +void foo7 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  a[0] = copysignf (b[0], c[0]);
> +}
> +
> +void foo8 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  a[0] = copysign (b[0], c[0]);
> +}
> +
> +void foo9 (_Float16* __restrict a, _Float16* b, _Float16* c)
> +{
> +  a[0] = copysignl (b[0], c[0]);
> +}
> +
> +void foo10 (float* __restrict a, float* b, float* c)
> +{
> +  a[0] = copysign (b[0], c[0]);
> +}
> +
> +void foo11 (float* __restrict a, float* b, float* c)
> +{
> +  a[0] = copysignl (b[0], c[0]);
> +}
> +
> +void foo12 (double* __restrict a, double* b, double* c)
> +{
> +  a[0] = copysignl (b[0], c[0]);
> +}
> +
> +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
> +/* { dg-final { scan-assembler-not "vcvtss2sd" } } */
> +/* { dg-final { scan-assembler-not "fld" } } */
> +/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
> +/* { dg-final { scan-assembler-not "vcvtps2pd" } } */
> +/* { dg-final { scan-assembler-not "extendhfxf" } } */
> +/* { dg-final { scan-assembler-not "\\\{1to8\\\}" } } */
> +/* { dg-final { scan-tree-dump-times "\.COPYSIGN" 12 "optimized" } } */
> +/* { dg-final { scan-assembler-times "vpternlog" 12 } } */
> --
> 2.18.1
>

  parent reply	other threads:[~2021-11-04  7:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04  6:45 [PATCH 1/2] [Middle-end] Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a, b) liuhongt
2021-11-04  6:45 ` [PATCH 2/2] [i386] Extend vternlog define_insn_and_split to memory_operand to enable more optimziation liuhongt
2021-11-04  7:47 ` Richard Biener [this message]
2021-11-04 18:32 ` [PATCH 1/2] [Middle-end] Simplify (trunc)copysign((extend)a, (extend)b) to .COPYSIGN (a, b) Joseph Myers
2021-11-05  2:20   ` [PATCH] Add !flag_signaling_nans to simplifcation: (trunc)copysign((extend)a, (extend)b) to copysign " liuhongt
2021-11-05  9:48     ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc1p5pxoc7G5mJVOG9V+eCDZkdhE7ev=VEu5FcKpw8R7Ng@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=crazylht@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=hongtao.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).