public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value.
@ 2021-10-25  5:59 liuhongt
  2021-10-25  8:33 ` Hongtao Liu
  0 siblings, 1 reply; 3+ messages in thread
From: liuhongt @ 2021-10-25  5:59 UTC (permalink / raw)
  To: gcc-patches

Similar for sqrt/sqrtl.

gcc/ChangeLog:

	PR target/102464
	* match.pd: Simplify (_Float16) sqrtf((float) a) to .SQRT(a)
	when direct_internal_fn_supported_p, similar for sqrt/sqrtl.

gcc/testsuite/ChangeLog:

	PR target/102464
	* gcc.target/i386/pr102464-sqrtph.c: New test.
	* gcc.target/i386/pr102464-sqrtsh.c: New test.
---
 gcc/match.pd                                  |  6 +++--
 .../gcc.target/i386/pr102464-sqrtph.c         | 27 +++++++++++++++++++
 .../gcc.target/i386/pr102464-sqrtsh.c         | 23 ++++++++++++++++
 3 files changed, 54 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 5bed2e12715..43d1c1bc0bd 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6228,14 +6228,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 	    BUILT_IN_ROUNDEVENL BUILT_IN_ROUNDEVEN BUILT_IN_ROUNDEVENF
 	    BUILT_IN_ROUNDL BUILT_IN_ROUND BUILT_IN_ROUNDF
 	    BUILT_IN_NEARBYINTL BUILT_IN_NEARBYINT BUILT_IN_NEARBYINTF
-	    BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF)
+	    BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF
+	    BUILT_IN_SQRTL BUILT_IN_SQRT BUILT_IN_SQRTF)
      tos (IFN_TRUNC IFN_TRUNC IFN_TRUNC
 	  IFN_FLOOR IFN_FLOOR IFN_FLOOR
 	  IFN_CEIL IFN_CEIL IFN_CEIL
 	  IFN_ROUNDEVEN IFN_ROUNDEVEN IFN_ROUNDEVEN
 	  IFN_ROUND IFN_ROUND IFN_ROUND
 	  IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT
-	  IFN_RINT IFN_RINT IFN_RINT)
+	  IFN_RINT IFN_RINT IFN_RINT
+	  IFN_SQRT IFN_SQRT IFN_SQRT)
  /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc.,
     if x is a _Float16.  */
  (simplify
diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
new file mode 100644
index 00000000000..8bd19c6e65e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
@@ -0,0 +1,27 @@
+/* PR target/102464.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize" } */
+
+#include<math.h>
+void foo1 (_Float16* __restrict a, _Float16* b)
+{
+  for (int i = 0; i != 8; i++)
+    a[i] =  sqrtf (b[i]);
+}
+
+void foo2 (_Float16* __restrict a, _Float16* b)
+{
+  for (int i = 0; i != 8; i++)
+    a[i] =  sqrt (b[i]);
+}
+
+void foo3 (_Float16* __restrict a, _Float16* b)
+{
+  for (int i = 0; i != 8; i++)
+    a[i] =  sqrtl (b[i]);
+}
+
+/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
+/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
+/* { dg-final { scan-assembler-not "extendhfxf" } } */
+/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 3 } } */
diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
new file mode 100644
index 00000000000..4cf0089a67f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
@@ -0,0 +1,23 @@
+/* PR target/102464.  */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -ffast-math" } */
+
+#include<math.h>
+_Float16 foo1 (_Float16 a)
+{
+  return sqrtf (a);
+}
+
+_Float16 foo2 (_Float16 a)
+{
+  return sqrt (a);
+}
+
+_Float16 foo3 (_Float16 a)
+{
+  return sqrtl (a);
+}
+
+/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
+/* { dg-final { scan-assembler-not "extendhfxf" } } */
+/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 3 } } */
-- 
2.18.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value.
  2021-10-25  5:59 [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value liuhongt
@ 2021-10-25  8:33 ` Hongtao Liu
  2021-10-25  8:50   ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Hongtao Liu @ 2021-10-25  8:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, H. J. Lu, liuhongt

On Mon, Oct 25, 2021 at 1:59 PM liuhongt <hongtao.liu@intel.com> wrote:
>
> Similar for sqrt/sqrtl.
>
  Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
  Ok for trunk?

> gcc/ChangeLog:
>
>         PR target/102464
>         * match.pd: Simplify (_Float16) sqrtf((float) a) to .SQRT(a)
>         when direct_internal_fn_supported_p, similar for sqrt/sqrtl.
>
> gcc/testsuite/ChangeLog:
>
>         PR target/102464
>         * gcc.target/i386/pr102464-sqrtph.c: New test.
>         * gcc.target/i386/pr102464-sqrtsh.c: New test.
> ---
>  gcc/match.pd                                  |  6 +++--
>  .../gcc.target/i386/pr102464-sqrtph.c         | 27 +++++++++++++++++++
>  .../gcc.target/i386/pr102464-sqrtsh.c         | 23 ++++++++++++++++
>  3 files changed, 54 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 5bed2e12715..43d1c1bc0bd 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6228,14 +6228,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>             BUILT_IN_ROUNDEVENL BUILT_IN_ROUNDEVEN BUILT_IN_ROUNDEVENF
>             BUILT_IN_ROUNDL BUILT_IN_ROUND BUILT_IN_ROUNDF
>             BUILT_IN_NEARBYINTL BUILT_IN_NEARBYINT BUILT_IN_NEARBYINTF
> -           BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF)
> +           BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF
> +           BUILT_IN_SQRTL BUILT_IN_SQRT BUILT_IN_SQRTF)
>       tos (IFN_TRUNC IFN_TRUNC IFN_TRUNC
>           IFN_FLOOR IFN_FLOOR IFN_FLOOR
>           IFN_CEIL IFN_CEIL IFN_CEIL
>           IFN_ROUNDEVEN IFN_ROUNDEVEN IFN_ROUNDEVEN
>           IFN_ROUND IFN_ROUND IFN_ROUND
>           IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT
> -         IFN_RINT IFN_RINT IFN_RINT)
> +         IFN_RINT IFN_RINT IFN_RINT
> +         IFN_SQRT IFN_SQRT IFN_SQRT)
>   /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc.,
>      if x is a _Float16.  */
>   (simplify
> diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
> new file mode 100644
> index 00000000000..8bd19c6e65e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
> @@ -0,0 +1,27 @@
> +/* PR target/102464.  */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize" } */
> +
> +#include<math.h>
> +void foo1 (_Float16* __restrict a, _Float16* b)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] =  sqrtf (b[i]);
> +}
> +
> +void foo2 (_Float16* __restrict a, _Float16* b)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] =  sqrt (b[i]);
> +}
> +
> +void foo3 (_Float16* __restrict a, _Float16* b)
> +{
> +  for (int i = 0; i != 8; i++)
> +    a[i] =  sqrtl (b[i]);
> +}
> +
> +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
> +/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
> +/* { dg-final { scan-assembler-not "extendhfxf" } } */
> +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 3 } } */
> diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
> new file mode 100644
> index 00000000000..4cf0089a67f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
> @@ -0,0 +1,23 @@
> +/* PR target/102464.  */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx512fp16 -ffast-math" } */
> +
> +#include<math.h>
> +_Float16 foo1 (_Float16 a)
> +{
> +  return sqrtf (a);
> +}
> +
> +_Float16 foo2 (_Float16 a)
> +{
> +  return sqrt (a);
> +}
> +
> +_Float16 foo3 (_Float16 a)
> +{
> +  return sqrtl (a);
> +}
> +
> +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
> +/* { dg-final { scan-assembler-not "extendhfxf" } } */
> +/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 3 } } */
> --
> 2.18.1
>


-- 
BR,
Hongtao

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value.
  2021-10-25  8:33 ` Hongtao Liu
@ 2021-10-25  8:50   ` Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2021-10-25  8:50 UTC (permalink / raw)
  To: Hongtao Liu; +Cc: GCC Patches, H. J. Lu, liuhongt

On Mon, Oct 25, 2021 at 10:26 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Mon, Oct 25, 2021 at 1:59 PM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > Similar for sqrt/sqrtl.
> >
>   Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}
>   Ok for trunk?

OK.

> > gcc/ChangeLog:
> >
> >         PR target/102464
> >         * match.pd: Simplify (_Float16) sqrtf((float) a) to .SQRT(a)
> >         when direct_internal_fn_supported_p, similar for sqrt/sqrtl.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         PR target/102464
> >         * gcc.target/i386/pr102464-sqrtph.c: New test.
> >         * gcc.target/i386/pr102464-sqrtsh.c: New test.
> > ---
> >  gcc/match.pd                                  |  6 +++--
> >  .../gcc.target/i386/pr102464-sqrtph.c         | 27 +++++++++++++++++++
> >  .../gcc.target/i386/pr102464-sqrtsh.c         | 23 ++++++++++++++++
> >  3 files changed, 54 insertions(+), 2 deletions(-)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index 5bed2e12715..43d1c1bc0bd 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6228,14 +6228,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> >             BUILT_IN_ROUNDEVENL BUILT_IN_ROUNDEVEN BUILT_IN_ROUNDEVENF
> >             BUILT_IN_ROUNDL BUILT_IN_ROUND BUILT_IN_ROUNDF
> >             BUILT_IN_NEARBYINTL BUILT_IN_NEARBYINT BUILT_IN_NEARBYINTF
> > -           BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF)
> > +           BUILT_IN_RINTL BUILT_IN_RINT BUILT_IN_RINTF
> > +           BUILT_IN_SQRTL BUILT_IN_SQRT BUILT_IN_SQRTF)
> >       tos (IFN_TRUNC IFN_TRUNC IFN_TRUNC
> >           IFN_FLOOR IFN_FLOOR IFN_FLOOR
> >           IFN_CEIL IFN_CEIL IFN_CEIL
> >           IFN_ROUNDEVEN IFN_ROUNDEVEN IFN_ROUNDEVEN
> >           IFN_ROUND IFN_ROUND IFN_ROUND
> >           IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT
> > -         IFN_RINT IFN_RINT IFN_RINT)
> > +         IFN_RINT IFN_RINT IFN_RINT
> > +         IFN_SQRT IFN_SQRT IFN_SQRT)
> >   /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc.,
> >      if x is a _Float16.  */
> >   (simplify
> > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
> > new file mode 100644
> > index 00000000000..8bd19c6e65e
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtph.c
> > @@ -0,0 +1,27 @@
> > +/* PR target/102464.  */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize" } */
> > +
> > +#include<math.h>
> > +void foo1 (_Float16* __restrict a, _Float16* b)
> > +{
> > +  for (int i = 0; i != 8; i++)
> > +    a[i] =  sqrtf (b[i]);
> > +}
> > +
> > +void foo2 (_Float16* __restrict a, _Float16* b)
> > +{
> > +  for (int i = 0; i != 8; i++)
> > +    a[i] =  sqrt (b[i]);
> > +}
> > +
> > +void foo3 (_Float16* __restrict a, _Float16* b)
> > +{
> > +  for (int i = 0; i != 8; i++)
> > +    a[i] =  sqrtl (b[i]);
> > +}
> > +
> > +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
> > +/* { dg-final { scan-assembler-not "vcvtph2p\[sd\]" } } */
> > +/* { dg-final { scan-assembler-not "extendhfxf" } } */
> > +/* { dg-final { scan-assembler-times "vsqrtph\[^\n\r\]*xmm\[0-9\]" 3 } } */
> > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
> > new file mode 100644
> > index 00000000000..4cf0089a67f
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr102464-sqrtsh.c
> > @@ -0,0 +1,23 @@
> > +/* PR target/102464.  */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mavx512fp16 -ffast-math" } */
> > +
> > +#include<math.h>
> > +_Float16 foo1 (_Float16 a)
> > +{
> > +  return sqrtf (a);
> > +}
> > +
> > +_Float16 foo2 (_Float16 a)
> > +{
> > +  return sqrt (a);
> > +}
> > +
> > +_Float16 foo3 (_Float16 a)
> > +{
> > +  return sqrtl (a);
> > +}
> > +
> > +/* { dg-final { scan-assembler-not "vcvtsh2s\[sd\]" } } */
> > +/* { dg-final { scan-assembler-not "extendhfxf" } } */
> > +/* { dg-final { scan-assembler-times "vsqrtsh\[^\n\r\]*xmm\[0-9\]" 3 } } */
> > --
> > 2.18.1
> >
>
>
> --
> BR,
> Hongtao

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-25  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25  5:59 [PATCH] Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value liuhongt
2021-10-25  8:33 ` Hongtao Liu
2021-10-25  8:50   ` 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).