[PATCH 2/2] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c).
liuhongt
hongtao.liu@intel.com
Fri Nov 5 05:38:51 GMT 2021
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
More information about the Gcc-patches
mailing list