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

https://gcc.gnu.org/g:2ad1e8081f4797a99a96b513ffe14c7305e9b3d8

commit r12-4984-g2ad1e8081f4797a99a96b513ffe14c7305e9b3d8
Author: liuhongt <hongtao.liu@intel.com>
Date:   Mon Nov 8 09:19:29 2021 +0800

    [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a,b, c).
    
    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.
    
    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.

Diff:
---
 gcc/match.pd                                 | 15 +++++++++++++
 gcc/testsuite/gcc.target/i386/pr102464-fma.c | 32 ++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 917833dd14b..869b26d16a0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6217,6 +6217,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 					  type, OPTIMIZE_FOR_BOTH))
     (IFN_COPYSIGN @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);


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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08  1:31 [gcc r12-4984] [Gimple] Simplify (trunc)fma ((extend)a, (extend)b, (extend)c) to IFN_FMA (a, b, c) 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).