public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5079] Simplify (trunc)MAX/MIN((extend)a, (extend)b) to MAX/MIN(a, b)
@ 2021-11-10  6:31 hongtao Liu
  0 siblings, 0 replies; only message in thread
From: hongtao Liu @ 2021-11-10  6:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b879d40a17ec0409f1a2cd9ab6134bb28f53eea8

commit r12-5079-gb879d40a17ec0409f1a2cd9ab6134bb28f53eea8
Author: liuhongt <hongtao.liu@intel.com>
Date:   Thu Nov 4 16:05:45 2021 +0800

    Simplify (trunc)MAX/MIN((extend)a, (extend)b) to MAX/MIN(a,b)
    
    a and b are same type as trunc type and has less precision than
    extend type.
    
    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.

Diff:
---
 gcc/match.pd                                    | 11 +++++++
 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 986b052bc93..7826af1998a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6243,6 +6243,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && direct_internal_fn_supported_p (as_internal_fn (tos),
 					  type, OPTIMIZE_FOR_BOTH))
     (tos @0 @1 @2))))
+
+(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))
+       && element_precision (type) < element_precision (TREE_TYPE (@2)))
+    (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);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-10  6:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10  6:31 [gcc r12-5079] Simplify (trunc)MAX/MIN((extend)a, (extend)b) to MAX/MIN(a, b) 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).