* [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a, b)
@ 2021-11-05 5:38 liuhongt
2021-11-05 5:38 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c) liuhongt
2021-11-05 9:52 ` [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b) Richard Biener
0 siblings, 2 replies; 9+ messages in thread
From: liuhongt @ 2021-11-05 5:38 UTC (permalink / raw)
To: gcc-patches
a and b are same type as trunc type and has less precision than
extend type, the transformation is guarded by flag_finite_math_only.
Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
Ok for trunk?
gcc/ChangeLog:
PR target/102464
* match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
MAX/MIN(a,b)
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr102464-maxmin.c: New test.
---
gcc/match.pd | 14 ++++++
.../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
diff --git a/gcc/match.pd b/gcc/match.pd
index f63079023d0..857ce7f712a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& direct_internal_fn_supported_p (IFN_COPYSIGN,
type, OPTIMIZE_FOR_BOTH))
(IFN_COPYSIGN @0 @1))))
+
+(for maxmin (max min)
+ (simplify
+ (convert (maxmin (convert@2 @0) (convert @1)))
+ (if (flag_finite_math_only
+ && optimize
+ && FLOAT_TYPE_P (type)
+ && FLOAT_TYPE_P (TREE_TYPE (@2))
+ && types_match (type, TREE_TYPE (@0))
+ && types_match (type, TREE_TYPE (@1))
+ && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
+ && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
+ TYPE_MODE (type)) != CODE_FOR_nothing)
+ (maxmin @0 @1))))
#endif
(for froms (XFLOORL XCEILL XROUNDL XRINTL)
diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
new file mode 100644
index 00000000000..37867235a6c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
@@ -0,0 +1,44 @@
+/* PR target/102464. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
+/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
+/* { dg-final { scan-assembler-times "vminph" 3 } } */
+/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
+/* { dg-final { scan-assembler-times "vminsh" 3 } } */
+/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
+/* { dg-final { scan-assembler-times "vminps" 2 } } */
+/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
+/* { dg-final { scan-assembler-times "vminss" 2 } } */
+/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
+/* { dg-final { scan-assembler-times "vminpd" 1 } } */
+/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
+/* { dg-final { scan-assembler-times "vminsd" 1 } } */
+
+#include<math.h>
+#define FOO(CODE,TYPE,SUFFIX) \
+ void \
+ foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
+ { \
+ for (int i = 0; i != 8; i++) \
+ a[i] = CODE##SUFFIX (b[i], c[i]); \
+ } \
+ TYPE \
+ foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
+ { \
+ return CODE##l (b, c); \
+ }
+
+FOO (fmax, _Float16, f);
+FOO (fmax, _Float16,);
+FOO (fmax, _Float16, l);
+FOO (fmin, _Float16, f);
+FOO (fmin, _Float16,);
+FOO (fmin, _Float16, l);
+
+FOO (fmax, float,);
+FOO (fmax, float, l);
+FOO (fmin, float,);
+FOO (fmin, float, l);
+
+FOO (fmax, double, l);
+FOO (fmin, double, l);
--
2.18.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c).
2021-11-05 5:38 [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a, b) liuhongt
@ 2021-11-05 5:38 ` liuhongt
2021-11-05 9:54 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a,b, c) Richard Biener
2021-11-05 9:52 ` [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b) Richard Biener
1 sibling, 1 reply; 9+ messages in thread
From: liuhongt @ 2021-11-05 5:38 UTC (permalink / raw)
To: gcc-patches
a, b, c are same type as truncation type and has less precision than
extend type, the optimization is guarded under
flag_unsafe_math_optimizations.
Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
Ok for trunk?
gcc/ChangeLog:
PR target/102464
* match.pd: Simplify
(trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b,
c) under flag_unsafe_math_optimizations.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr102464-fma.c: New test.
---
gcc/match.pd | 16 ++++++++++
gcc/testsuite/gcc.target/i386/pr102464-fma.c | 32 ++++++++++++++++++++
2 files changed, 48 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-fma.c
diff --git a/gcc/match.pd b/gcc/match.pd
index 857ce7f712a..fb1065dc0e6 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6196,6 +6196,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
TYPE_MODE (type)) != CODE_FOR_nothing)
(maxmin @0 @1))))
+
+(for froms (BUILT_IN_FMAF BUILT_IN_FMA BUILT_IN_FMAL)
+ tos (IFN_FMA IFN_FMA IFN_FMA)
+ (simplify
+ (convert (froms (convert@3 @0) (convert @1) (convert @2)))
+ (if (flag_unsafe_math_optimizations
+ && optimize
+ && FLOAT_TYPE_P (type)
+ && FLOAT_TYPE_P (TREE_TYPE (@3))
+ && types_match (type, TREE_TYPE (@0))
+ && types_match (type, TREE_TYPE (@1))
+ && types_match (type, TREE_TYPE (@2))
+ && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@3))
+ && direct_internal_fn_supported_p (as_internal_fn (tos),
+ type, OPTIMIZE_FOR_BOTH))
+ (tos @0 @1 @2))))
#endif
(for froms (XFLOORL XCEILL XROUNDL XRINTL)
diff --git a/gcc/testsuite/gcc.target/i386/pr102464-fma.c b/gcc/testsuite/gcc.target/i386/pr102464-fma.c
new file mode 100644
index 00000000000..9c70d93d980
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr102464-fma.c
@@ -0,0 +1,32 @@
+/* PR target/102464. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
+/* { dg-final { scan-assembler-times "vfmadd...ph" 3 } } */
+/* { dg-final { scan-assembler-times "vfmadd...sh" 3 } } */
+/* { dg-final { scan-assembler-times "vfmadd...ps" 2 } } */
+/* { dg-final { scan-assembler-times "vfmadd...ss" 2 } } */
+/* { dg-final { scan-assembler-times "vfmadd...pd" 1 } } */
+/* { dg-final { scan-assembler-times "vfmadd...sd" 1 } } */
+
+#include<math.h>
+#define FOO(TYPE,SUFFIX) \
+ void \
+ foo_vect_##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c, TYPE* d) \
+ { \
+ for (int i = 0; i != 8; i++) \
+ a[i] = fma##SUFFIX (b[i], c[i], d[i]); \
+ } \
+ TYPE \
+ foo_##TYPE##SUFFIX (TYPE b, TYPE c, TYPE d) \
+ { \
+ return fma##l (b, c, d); \
+ }
+
+FOO (_Float16, f);
+FOO (_Float16,);
+FOO (_Float16, l);
+
+FOO (float,);
+FOO (float, l);
+
+FOO (double, l);
--
2.18.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-05 5:38 [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a, b) liuhongt
2021-11-05 5:38 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c) liuhongt
@ 2021-11-05 9:52 ` Richard Biener
2021-11-08 1:36 ` Hongtao Liu
1 sibling, 1 reply; 9+ messages in thread
From: Richard Biener @ 2021-11-05 9:52 UTC (permalink / raw)
To: liuhongt; +Cc: GCC Patches, Hongtao Liu, H. J. Lu
On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> a and b are same type as trunc type and has less precision than
> extend type, the transformation is guarded by flag_finite_math_only.
>
> Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> Ok for trunk?
>
> gcc/ChangeLog:
>
> PR target/102464
> * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> MAX/MIN(a,b)
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr102464-maxmin.c: New test.
> ---
> gcc/match.pd | 14 ++++++
> .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> 2 files changed, 58 insertions(+)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index f63079023d0..857ce7f712a 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> && direct_internal_fn_supported_p (IFN_COPYSIGN,
> type, OPTIMIZE_FOR_BOTH))
> (IFN_COPYSIGN @0 @1))))
> +
> +(for maxmin (max min)
> + (simplify
> + (convert (maxmin (convert@2 @0) (convert @1)))
> + (if (flag_finite_math_only
I suppose you are concerned about infinities, not about NaNs.
Please use !HONOR_INFINITIES (@2) then (in general testing
flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
tests first.
> + && optimize
> + && FLOAT_TYPE_P (type)
> + && FLOAT_TYPE_P (TREE_TYPE (@2))
> + && types_match (type, TREE_TYPE (@0))
> + && types_match (type, TREE_TYPE (@1))
> + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> + TYPE_MODE (type)) != CODE_FOR_nothing)
> + (maxmin @0 @1))))
> #endif
>
> (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> new file mode 100644
> index 00000000000..37867235a6c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> @@ -0,0 +1,44 @@
> +/* PR target/102464. */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> +
> +#include<math.h>
> +#define FOO(CODE,TYPE,SUFFIX) \
> + void \
> + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> + { \
> + for (int i = 0; i != 8; i++) \
> + a[i] = CODE##SUFFIX (b[i], c[i]); \
> + } \
> + TYPE \
> + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> + { \
> + return CODE##l (b, c); \
> + }
> +
> +FOO (fmax, _Float16, f);
> +FOO (fmax, _Float16,);
> +FOO (fmax, _Float16, l);
> +FOO (fmin, _Float16, f);
> +FOO (fmin, _Float16,);
> +FOO (fmin, _Float16, l);
> +
> +FOO (fmax, float,);
> +FOO (fmax, float, l);
> +FOO (fmin, float,);
> +FOO (fmin, float, l);
> +
> +FOO (fmax, double, l);
> +FOO (fmin, double, l);
> --
> 2.18.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a,b, c).
2021-11-05 5:38 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c) liuhongt
@ 2021-11-05 9:54 ` Richard Biener
0 siblings, 0 replies; 9+ messages in thread
From: Richard Biener @ 2021-11-05 9:54 UTC (permalink / raw)
To: liuhongt; +Cc: GCC Patches, Hongtao Liu, H. J. Lu
On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
>
> a, b, c are same type as truncation type and has less precision than
> extend type, the optimization is guarded under
> flag_unsafe_math_optimizations.
>
> Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> Ok for trunk?
OK.
Thanks,
Richard.
> gcc/ChangeLog:
> PR target/102464
> * match.pd: Simplify
> (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b,
> c) under flag_unsafe_math_optimizations.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr102464-fma.c: New test.
> ---
> gcc/match.pd | 16 ++++++++++
> gcc/testsuite/gcc.target/i386/pr102464-fma.c | 32 ++++++++++++++++++++
> 2 files changed, 48 insertions(+)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-fma.c
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 857ce7f712a..fb1065dc0e6 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -6196,6 +6196,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> TYPE_MODE (type)) != CODE_FOR_nothing)
> (maxmin @0 @1))))
> +
> +(for froms (BUILT_IN_FMAF BUILT_IN_FMA BUILT_IN_FMAL)
> + tos (IFN_FMA IFN_FMA IFN_FMA)
> + (simplify
> + (convert (froms (convert@3 @0) (convert @1) (convert @2)))
> + (if (flag_unsafe_math_optimizations
> + && optimize
> + && FLOAT_TYPE_P (type)
> + && FLOAT_TYPE_P (TREE_TYPE (@3))
> + && types_match (type, TREE_TYPE (@0))
> + && types_match (type, TREE_TYPE (@1))
> + && types_match (type, TREE_TYPE (@2))
> + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@3))
> + && direct_internal_fn_supported_p (as_internal_fn (tos),
> + type, OPTIMIZE_FOR_BOTH))
> + (tos @0 @1 @2))))
> #endif
>
> (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> diff --git a/gcc/testsuite/gcc.target/i386/pr102464-fma.c b/gcc/testsuite/gcc.target/i386/pr102464-fma.c
> new file mode 100644
> index 00000000000..9c70d93d980
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr102464-fma.c
> @@ -0,0 +1,32 @@
> +/* PR target/102464. */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> +/* { dg-final { scan-assembler-times "vfmadd...ph" 3 } } */
> +/* { dg-final { scan-assembler-times "vfmadd...sh" 3 } } */
> +/* { dg-final { scan-assembler-times "vfmadd...ps" 2 } } */
> +/* { dg-final { scan-assembler-times "vfmadd...ss" 2 } } */
> +/* { dg-final { scan-assembler-times "vfmadd...pd" 1 } } */
> +/* { dg-final { scan-assembler-times "vfmadd...sd" 1 } } */
> +
> +#include<math.h>
> +#define FOO(TYPE,SUFFIX) \
> + void \
> + foo_vect_##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c, TYPE* d) \
> + { \
> + for (int i = 0; i != 8; i++) \
> + a[i] = fma##SUFFIX (b[i], c[i], d[i]); \
> + } \
> + TYPE \
> + foo_##TYPE##SUFFIX (TYPE b, TYPE c, TYPE d) \
> + { \
> + return fma##l (b, c, d); \
> + }
> +
> +FOO (_Float16, f);
> +FOO (_Float16,);
> +FOO (_Float16, l);
> +
> +FOO (float,);
> +FOO (float, l);
> +
> +FOO (double, l);
> --
> 2.18.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-05 9:52 ` [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b) Richard Biener
@ 2021-11-08 1:36 ` Hongtao Liu
2021-11-08 8:59 ` Richard Biener
0 siblings, 1 reply; 9+ messages in thread
From: Hongtao Liu @ 2021-11-08 1:36 UTC (permalink / raw)
To: Richard Biener; +Cc: liuhongt, GCC Patches, H. J. Lu
On Fri, Nov 5, 2021 at 5:52 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > a and b are same type as trunc type and has less precision than
> > extend type, the transformation is guarded by flag_finite_math_only.
> >
> > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> > Ok for trunk?
> >
> > gcc/ChangeLog:
> >
> > PR target/102464
> > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> > MAX/MIN(a,b)
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/i386/pr102464-maxmin.c: New test.
> > ---
> > gcc/match.pd | 14 ++++++
> > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> > 2 files changed, 58 insertions(+)
> > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> >
> > diff --git a/gcc/match.pd b/gcc/match.pd
> > index f63079023d0..857ce7f712a 100644
> > --- a/gcc/match.pd
> > +++ b/gcc/match.pd
> > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > && direct_internal_fn_supported_p (IFN_COPYSIGN,
> > type, OPTIMIZE_FOR_BOTH))
> > (IFN_COPYSIGN @0 @1))))
> > +
> > +(for maxmin (max min)
> > + (simplify
> > + (convert (maxmin (convert@2 @0) (convert @1)))
> > + (if (flag_finite_math_only
>
> I suppose you are concerned about infinities, not about NaNs.
> Please use !HONOR_INFINITIES (@2) then (in general testing
> flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
> tests first.
I'm concerned about NANs since MAX/MIN_EXPR are different from IEEE
minimum and maximum operations at NAN operations.
So i think i'd use MODE_HAS_NANS(@2)?
>
> > + && optimize
> > + && FLOAT_TYPE_P (type)
> > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > + && types_match (type, TREE_TYPE (@0))
> > + && types_match (type, TREE_TYPE (@1))
> > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> > + TYPE_MODE (type)) != CODE_FOR_nothing)
> > + (maxmin @0 @1))))
> > #endif
> >
> > (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > new file mode 100644
> > index 00000000000..37867235a6c
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > @@ -0,0 +1,44 @@
> > +/* PR target/102464. */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> > +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> > +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> > +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> > +
> > +#include<math.h>
> > +#define FOO(CODE,TYPE,SUFFIX) \
> > + void \
> > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> > + { \
> > + for (int i = 0; i != 8; i++) \
> > + a[i] = CODE##SUFFIX (b[i], c[i]); \
> > + } \
> > + TYPE \
> > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> > + { \
> > + return CODE##l (b, c); \
> > + }
> > +
> > +FOO (fmax, _Float16, f);
> > +FOO (fmax, _Float16,);
> > +FOO (fmax, _Float16, l);
> > +FOO (fmin, _Float16, f);
> > +FOO (fmin, _Float16,);
> > +FOO (fmin, _Float16, l);
> > +
> > +FOO (fmax, float,);
> > +FOO (fmax, float, l);
> > +FOO (fmin, float,);
> > +FOO (fmin, float, l);
> > +
> > +FOO (fmax, double, l);
> > +FOO (fmin, double, l);
> > --
> > 2.18.1
> >
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-08 1:36 ` Hongtao Liu
@ 2021-11-08 8:59 ` Richard Biener
2021-11-09 2:44 ` Hongtao Liu
0 siblings, 1 reply; 9+ messages in thread
From: Richard Biener @ 2021-11-08 8:59 UTC (permalink / raw)
To: Hongtao Liu; +Cc: liuhongt, GCC Patches, H. J. Lu
On Mon, Nov 8, 2021 at 2:30 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Fri, Nov 5, 2021 at 5:52 PM Richard Biener
> <richard.guenther@gmail.com> wrote:
> >
> > On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
> > >
> > > a and b are same type as trunc type and has less precision than
> > > extend type, the transformation is guarded by flag_finite_math_only.
> > >
> > > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> > > Ok for trunk?
> > >
> > > gcc/ChangeLog:
> > >
> > > PR target/102464
> > > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> > > MAX/MIN(a,b)
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.target/i386/pr102464-maxmin.c: New test.
> > > ---
> > > gcc/match.pd | 14 ++++++
> > > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> > > 2 files changed, 58 insertions(+)
> > > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > >
> > > diff --git a/gcc/match.pd b/gcc/match.pd
> > > index f63079023d0..857ce7f712a 100644
> > > --- a/gcc/match.pd
> > > +++ b/gcc/match.pd
> > > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > > && direct_internal_fn_supported_p (IFN_COPYSIGN,
> > > type, OPTIMIZE_FOR_BOTH))
> > > (IFN_COPYSIGN @0 @1))))
> > > +
> > > +(for maxmin (max min)
> > > + (simplify
> > > + (convert (maxmin (convert@2 @0) (convert @1)))
> > > + (if (flag_finite_math_only
> >
> > I suppose you are concerned about infinities, not about NaNs.
> > Please use !HONOR_INFINITIES (@2) then (in general testing
> > flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
> > tests first.
> I'm concerned about NANs since MAX/MIN_EXPR are different from IEEE
> minimum and maximum operations at NAN operations.
But you are already only handling non-IEEE MAX/MIN_EXPR where the
behavior with a NaN argument is unspecified?
> So i think i'd use MODE_HAS_NANS(@2)?
> >
> > > + && optimize
> > > + && FLOAT_TYPE_P (type)
> > > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > > + && types_match (type, TREE_TYPE (@0))
> > > + && types_match (type, TREE_TYPE (@1))
> > > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> > > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> > > + TYPE_MODE (type)) != CODE_FOR_nothing)
And just noticing this now - since we're only changing the type a MAX/MIN_EXPR
operate on, we don't really need to do the optab check. At RTL expansion
we'd eventually try a wider mode.
> > > + (maxmin @0 @1))))
> > > #endif
> > >
> > > (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> > > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > new file mode 100644
> > > index 00000000000..37867235a6c
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > @@ -0,0 +1,44 @@
> > > +/* PR target/102464. */
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> > > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> > > +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> > > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> > > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> > > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> > > +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> > > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> > > +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> > > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> > > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> > > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> > > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> > > +
> > > +#include<math.h>
> > > +#define FOO(CODE,TYPE,SUFFIX) \
> > > + void \
> > > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> > > + { \
> > > + for (int i = 0; i != 8; i++) \
> > > + a[i] = CODE##SUFFIX (b[i], c[i]); \
> > > + } \
> > > + TYPE \
> > > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> > > + { \
> > > + return CODE##l (b, c); \
> > > + }
> > > +
> > > +FOO (fmax, _Float16, f);
> > > +FOO (fmax, _Float16,);
> > > +FOO (fmax, _Float16, l);
> > > +FOO (fmin, _Float16, f);
> > > +FOO (fmin, _Float16,);
> > > +FOO (fmin, _Float16, l);
> > > +
> > > +FOO (fmax, float,);
> > > +FOO (fmax, float, l);
> > > +FOO (fmin, float,);
> > > +FOO (fmin, float, l);
> > > +
> > > +FOO (fmax, double, l);
> > > +FOO (fmin, double, l);
> > > --
> > > 2.18.1
> > >
>
>
>
> --
> BR,
> Hongtao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-08 8:59 ` Richard Biener
@ 2021-11-09 2:44 ` Hongtao Liu
2021-11-09 10:21 ` Richard Biener
0 siblings, 1 reply; 9+ messages in thread
From: Hongtao Liu @ 2021-11-09 2:44 UTC (permalink / raw)
To: Richard Biener; +Cc: liuhongt, GCC Patches, H. J. Lu
On Mon, Nov 8, 2021 at 4:59 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Mon, Nov 8, 2021 at 2:30 AM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Fri, Nov 5, 2021 at 5:52 PM Richard Biener
> > <richard.guenther@gmail.com> wrote:
> > >
> > > On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
> > > >
> > > > a and b are same type as trunc type and has less precision than
> > > > extend type, the transformation is guarded by flag_finite_math_only.
> > > >
> > > > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> > > > Ok for trunk?
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > PR target/102464
> > > > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> > > > MAX/MIN(a,b)
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > * gcc.target/i386/pr102464-maxmin.c: New test.
> > > > ---
> > > > gcc/match.pd | 14 ++++++
> > > > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> > > > 2 files changed, 58 insertions(+)
> > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > >
> > > > diff --git a/gcc/match.pd b/gcc/match.pd
> > > > index f63079023d0..857ce7f712a 100644
> > > > --- a/gcc/match.pd
> > > > +++ b/gcc/match.pd
> > > > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > > > && direct_internal_fn_supported_p (IFN_COPYSIGN,
> > > > type, OPTIMIZE_FOR_BOTH))
> > > > (IFN_COPYSIGN @0 @1))))
> > > > +
> > > > +(for maxmin (max min)
> > > > + (simplify
> > > > + (convert (maxmin (convert@2 @0) (convert @1)))
> > > > + (if (flag_finite_math_only
> > >
> > > I suppose you are concerned about infinities, not about NaNs.
> > > Please use !HONOR_INFINITIES (@2) then (in general testing
> > > flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
> > > tests first.
> > I'm concerned about NANs since MAX/MIN_EXPR are different from IEEE
> > minimum and maximum operations at NAN operations.
>
> But you are already only handling non-IEEE MAX/MIN_EXPR where the
> behavior with a NaN argument is unspecified?
Oh yes, it's already guarded by
/* Convert fmin/fmax to MIN_EXPR/MAX_EXPR. C99 requires these
functions to return the numeric arg if the other one is NaN.
MIN and MAX don't honor that, so only transform if -ffinite-math-only
is set. C99 doesn't require -0.0 to be handled, so we don't have to
worry about it either. */
(if (flag_finite_math_only)
(simplify
>
> > So i think i'd use MODE_HAS_NANS(@2)?
> > >
> > > > + && optimize
> > > > + && FLOAT_TYPE_P (type)
> > > > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > > > + && types_match (type, TREE_TYPE (@0))
> > > > + && types_match (type, TREE_TYPE (@1))
> > > > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> > > > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> > > > + TYPE_MODE (type)) != CODE_FOR_nothing)
>
> And just noticing this now - since we're only changing the type a MAX/MIN_EXPR
> operate on, we don't really need to do the optab check. At RTL expansion
> we'd eventually try a wider mode.
Changed.
Updated:
+
+(for maxmin (max min)
+ (simplify
+ (convert (maxmin (convert@2 @0) (convert @1)))
+ (if (optimize
+ && FLOAT_TYPE_P (type)
+ && FLOAT_TYPE_P (TREE_TYPE (@2))
+ && types_match (type, TREE_TYPE (@0))
+ && types_match (type, TREE_TYPE (@1))
+ && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2)))
+ (maxmin @0 @1))))
>
> > > > + (maxmin @0 @1))))
> > > > #endif
> > > >
> > > > (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> > > > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > new file mode 100644
> > > > index 00000000000..37867235a6c
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > @@ -0,0 +1,44 @@
> > > > +/* PR target/102464. */
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> > > > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> > > > +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> > > > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> > > > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> > > > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> > > > +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> > > > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> > > > +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> > > > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> > > > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> > > > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> > > > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> > > > +
> > > > +#include<math.h>
> > > > +#define FOO(CODE,TYPE,SUFFIX) \
> > > > + void \
> > > > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> > > > + { \
> > > > + for (int i = 0; i != 8; i++) \
> > > > + a[i] = CODE##SUFFIX (b[i], c[i]); \
> > > > + } \
> > > > + TYPE \
> > > > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> > > > + { \
> > > > + return CODE##l (b, c); \
> > > > + }
> > > > +
> > > > +FOO (fmax, _Float16, f);
> > > > +FOO (fmax, _Float16,);
> > > > +FOO (fmax, _Float16, l);
> > > > +FOO (fmin, _Float16, f);
> > > > +FOO (fmin, _Float16,);
> > > > +FOO (fmin, _Float16, l);
> > > > +
> > > > +FOO (fmax, float,);
> > > > +FOO (fmax, float, l);
> > > > +FOO (fmin, float,);
> > > > +FOO (fmin, float, l);
> > > > +
> > > > +FOO (fmax, double, l);
> > > > +FOO (fmin, double, l);
> > > > --
> > > > 2.18.1
> > > >
> >
> >
> >
> > --
> > BR,
> > Hongtao
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-09 2:44 ` Hongtao Liu
@ 2021-11-09 10:21 ` Richard Biener
2021-11-10 6:31 ` Hongtao Liu
0 siblings, 1 reply; 9+ messages in thread
From: Richard Biener @ 2021-11-09 10:21 UTC (permalink / raw)
To: Hongtao Liu; +Cc: liuhongt, GCC Patches, H. J. Lu
On Tue, Nov 9, 2021 at 3:37 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Mon, Nov 8, 2021 at 4:59 PM Richard Biener
> <richard.guenther@gmail.com> wrote:
> >
> > On Mon, Nov 8, 2021 at 2:30 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Fri, Nov 5, 2021 at 5:52 PM Richard Biener
> > > <richard.guenther@gmail.com> wrote:
> > > >
> > > > On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
> > > > >
> > > > > a and b are same type as trunc type and has less precision than
> > > > > extend type, the transformation is guarded by flag_finite_math_only.
> > > > >
> > > > > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> > > > > Ok for trunk?
> > > > >
> > > > > gcc/ChangeLog:
> > > > >
> > > > > PR target/102464
> > > > > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> > > > > MAX/MIN(a,b)
> > > > >
> > > > > gcc/testsuite/ChangeLog:
> > > > >
> > > > > * gcc.target/i386/pr102464-maxmin.c: New test.
> > > > > ---
> > > > > gcc/match.pd | 14 ++++++
> > > > > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> > > > > 2 files changed, 58 insertions(+)
> > > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > >
> > > > > diff --git a/gcc/match.pd b/gcc/match.pd
> > > > > index f63079023d0..857ce7f712a 100644
> > > > > --- a/gcc/match.pd
> > > > > +++ b/gcc/match.pd
> > > > > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > > > > && direct_internal_fn_supported_p (IFN_COPYSIGN,
> > > > > type, OPTIMIZE_FOR_BOTH))
> > > > > (IFN_COPYSIGN @0 @1))))
> > > > > +
> > > > > +(for maxmin (max min)
> > > > > + (simplify
> > > > > + (convert (maxmin (convert@2 @0) (convert @1)))
> > > > > + (if (flag_finite_math_only
> > > >
> > > > I suppose you are concerned about infinities, not about NaNs.
> > > > Please use !HONOR_INFINITIES (@2) then (in general testing
> > > > flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
> > > > tests first.
> > > I'm concerned about NANs since MAX/MIN_EXPR are different from IEEE
> > > minimum and maximum operations at NAN operations.
> >
> > But you are already only handling non-IEEE MAX/MIN_EXPR where the
> > behavior with a NaN argument is unspecified?
> Oh yes, it's already guarded by
> /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR. C99 requires these
> functions to return the numeric arg if the other one is NaN.
> MIN and MAX don't honor that, so only transform if -ffinite-math-only
> is set. C99 doesn't require -0.0 to be handled, so we don't have to
> worry about it either. */
> (if (flag_finite_math_only)
> (simplify
>
> >
> > > So i think i'd use MODE_HAS_NANS(@2)?
> > > >
> > > > > + && optimize
> > > > > + && FLOAT_TYPE_P (type)
> > > > > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > > > > + && types_match (type, TREE_TYPE (@0))
> > > > > + && types_match (type, TREE_TYPE (@1))
> > > > > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> > > > > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> > > > > + TYPE_MODE (type)) != CODE_FOR_nothing)
> >
> > And just noticing this now - since we're only changing the type a MAX/MIN_EXPR
> > operate on, we don't really need to do the optab check. At RTL expansion
> > we'd eventually try a wider mode.
> Changed.
> Updated:
> +
> +(for maxmin (max min)
> + (simplify
> + (convert (maxmin (convert@2 @0) (convert @1)))
> + (if (optimize
> + && FLOAT_TYPE_P (type)
> + && FLOAT_TYPE_P (TREE_TYPE (@2))
> + && types_match (type, TREE_TYPE (@0))
> + && types_match (type, TREE_TYPE (@1))
> + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2)))
since FLOAT_TYPE_P also matches vector types please use
&& element_precision (type) < element_precision (TREE_TYPE (@2))
> + (maxmin @0 @1))))
OK with that change.
Thanks,
Richard.
> >
> > > > > + (maxmin @0 @1))))
> > > > > #endif
> > > > >
> > > > > (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> > > > > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > > new file mode 100644
> > > > > index 00000000000..37867235a6c
> > > > > --- /dev/null
> > > > > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > > @@ -0,0 +1,44 @@
> > > > > +/* PR target/102464. */
> > > > > +/* { dg-do compile } */
> > > > > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> > > > > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> > > > > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> > > > > +
> > > > > +#include<math.h>
> > > > > +#define FOO(CODE,TYPE,SUFFIX) \
> > > > > + void \
> > > > > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> > > > > + { \
> > > > > + for (int i = 0; i != 8; i++) \
> > > > > + a[i] = CODE##SUFFIX (b[i], c[i]); \
> > > > > + } \
> > > > > + TYPE \
> > > > > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> > > > > + { \
> > > > > + return CODE##l (b, c); \
> > > > > + }
> > > > > +
> > > > > +FOO (fmax, _Float16, f);
> > > > > +FOO (fmax, _Float16,);
> > > > > +FOO (fmax, _Float16, l);
> > > > > +FOO (fmin, _Float16, f);
> > > > > +FOO (fmin, _Float16,);
> > > > > +FOO (fmin, _Float16, l);
> > > > > +
> > > > > +FOO (fmax, float,);
> > > > > +FOO (fmax, float, l);
> > > > > +FOO (fmin, float,);
> > > > > +FOO (fmin, float, l);
> > > > > +
> > > > > +FOO (fmax, double, l);
> > > > > +FOO (fmin, double, l);
> > > > > --
> > > > > 2.18.1
> > > > >
> > >
> > >
> > >
> > > --
> > > BR,
> > > Hongtao
>
>
>
> --
> BR,
> Hongtao
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b)
2021-11-09 10:21 ` Richard Biener
@ 2021-11-10 6:31 ` Hongtao Liu
0 siblings, 0 replies; 9+ messages in thread
From: Hongtao Liu @ 2021-11-10 6:31 UTC (permalink / raw)
To: Richard Biener; +Cc: liuhongt, GCC Patches, H. J. Lu
On Tue, Nov 9, 2021 at 6:21 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Tue, Nov 9, 2021 at 3:37 AM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Mon, Nov 8, 2021 at 4:59 PM Richard Biener
> > <richard.guenther@gmail.com> wrote:
> > >
> > > On Mon, Nov 8, 2021 at 2:30 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > > >
> > > > On Fri, Nov 5, 2021 at 5:52 PM Richard Biener
> > > > <richard.guenther@gmail.com> wrote:
> > > > >
> > > > > On Fri, Nov 5, 2021 at 6:38 AM liuhongt <hongtao.liu@intel.com> wrote:
> > > > > >
> > > > > > a and b are same type as trunc type and has less precision than
> > > > > > extend type, the transformation is guarded by flag_finite_math_only.
> > > > > >
> > > > > > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,}
> > > > > > Ok for trunk?
> > > > > >
> > > > > > gcc/ChangeLog:
> > > > > >
> > > > > > PR target/102464
> > > > > > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to
> > > > > > MAX/MIN(a,b)
> > > > > >
> > > > > > gcc/testsuite/ChangeLog:
> > > > > >
> > > > > > * gcc.target/i386/pr102464-maxmin.c: New test.
> > > > > > ---
> > > > > > gcc/match.pd | 14 ++++++
> > > > > > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++
> > > > > > 2 files changed, 58 insertions(+)
> > > > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > > >
> > > > > > diff --git a/gcc/match.pd b/gcc/match.pd
> > > > > > index f63079023d0..857ce7f712a 100644
> > > > > > --- a/gcc/match.pd
> > > > > > +++ b/gcc/match.pd
> > > > > > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> > > > > > && direct_internal_fn_supported_p (IFN_COPYSIGN,
> > > > > > type, OPTIMIZE_FOR_BOTH))
> > > > > > (IFN_COPYSIGN @0 @1))))
> > > > > > +
> > > > > > +(for maxmin (max min)
> > > > > > + (simplify
> > > > > > + (convert (maxmin (convert@2 @0) (convert @1)))
> > > > > > + (if (flag_finite_math_only
> > > > >
> > > > > I suppose you are concerned about infinities, not about NaNs.
> > > > > Please use !HONOR_INFINITIES (@2) then (in general testing
> > > > > flag_* is frowned upon). You may want to do the FLOAT_TYPE_P
> > > > > tests first.
> > > > I'm concerned about NANs since MAX/MIN_EXPR are different from IEEE
> > > > minimum and maximum operations at NAN operations.
> > >
> > > But you are already only handling non-IEEE MAX/MIN_EXPR where the
> > > behavior with a NaN argument is unspecified?
> > Oh yes, it's already guarded by
> > /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR. C99 requires these
> > functions to return the numeric arg if the other one is NaN.
> > MIN and MAX don't honor that, so only transform if -ffinite-math-only
> > is set. C99 doesn't require -0.0 to be handled, so we don't have to
> > worry about it either. */
> > (if (flag_finite_math_only)
> > (simplify
> >
> > >
> > > > So i think i'd use MODE_HAS_NANS(@2)?
> > > > >
> > > > > > + && optimize
> > > > > > + && FLOAT_TYPE_P (type)
> > > > > > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > > > > > + && types_match (type, TREE_TYPE (@0))
> > > > > > + && types_match (type, TREE_TYPE (@1))
> > > > > > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2))
> > > > > > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab,
> > > > > > + TYPE_MODE (type)) != CODE_FOR_nothing)
> > >
> > > And just noticing this now - since we're only changing the type a MAX/MIN_EXPR
> > > operate on, we don't really need to do the optab check. At RTL expansion
> > > we'd eventually try a wider mode.
> > Changed.
> > Updated:
> > +
> > +(for maxmin (max min)
> > + (simplify
> > + (convert (maxmin (convert@2 @0) (convert @1)))
> > + (if (optimize
> > + && FLOAT_TYPE_P (type)
> > + && FLOAT_TYPE_P (TREE_TYPE (@2))
> > + && types_match (type, TREE_TYPE (@0))
> > + && types_match (type, TREE_TYPE (@1))
> > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2)))
>
> since FLOAT_TYPE_P also matches vector types please use
>
> && element_precision (type) < element_precision (TREE_TYPE (@2))
>
> > + (maxmin @0 @1))))
>
> OK with that change.
>
Yes, thanks for the review.
> Thanks,
> Richard.
>
> > >
> > > > > > + (maxmin @0 @1))))
> > > > > > #endif
> > > > > >
> > > > > > (for froms (XFLOORL XCEILL XROUNDL XRINTL)
> > > > > > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > > > new file mode 100644
> > > > > > index 00000000000..37867235a6c
> > > > > > --- /dev/null
> > > > > > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c
> > > > > > @@ -0,0 +1,44 @@
> > > > > > +/* PR target/102464. */
> > > > > > +/* { dg-do compile } */
> > > > > > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminph" 3 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminps" 2 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminss" 2 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */
> > > > > > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */
> > > > > > +
> > > > > > +#include<math.h>
> > > > > > +#define FOO(CODE,TYPE,SUFFIX) \
> > > > > > + void \
> > > > > > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \
> > > > > > + { \
> > > > > > + for (int i = 0; i != 8; i++) \
> > > > > > + a[i] = CODE##SUFFIX (b[i], c[i]); \
> > > > > > + } \
> > > > > > + TYPE \
> > > > > > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \
> > > > > > + { \
> > > > > > + return CODE##l (b, c); \
> > > > > > + }
> > > > > > +
> > > > > > +FOO (fmax, _Float16, f);
> > > > > > +FOO (fmax, _Float16,);
> > > > > > +FOO (fmax, _Float16, l);
> > > > > > +FOO (fmin, _Float16, f);
> > > > > > +FOO (fmin, _Float16,);
> > > > > > +FOO (fmin, _Float16, l);
> > > > > > +
> > > > > > +FOO (fmax, float,);
> > > > > > +FOO (fmax, float, l);
> > > > > > +FOO (fmin, float,);
> > > > > > +FOO (fmin, float, l);
> > > > > > +
> > > > > > +FOO (fmax, double, l);
> > > > > > +FOO (fmin, double, l);
> > > > > > --
> > > > > > 2.18.1
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > BR,
> > > > Hongtao
> >
> >
> >
> > --
> > BR,
> > Hongtao
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-11-10 6:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 5:38 [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a, b) liuhongt
2021-11-05 5:38 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c) liuhongt
2021-11-05 9:54 ` [PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a,b, c) Richard Biener
2021-11-05 9:52 ` [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b) Richard Biener
2021-11-08 1:36 ` Hongtao Liu
2021-11-08 8:59 ` Richard Biener
2021-11-09 2:44 ` Hongtao Liu
2021-11-09 10:21 ` Richard Biener
2021-11-10 6:31 ` Hongtao Liu
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).