Simplify (_Float16) sqrtf((float) a) to .SQRT(a) when a is a _Float16 value.
Commit Message
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
Comments
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
>
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
@@ -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
new file mode 100644
@@ -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 } } */
new file mode 100644
@@ -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 } } */