aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/match.pd11
-rw-r--r--gcc/testsuite/gcc.target/i386/pr102464-maxmin.c44
2 files changed, 55 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 986b052..7826af1 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 0000000..3786723
--- /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);