public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH] tree-optimization/112623 - forwprop VEC_PACK_TRUNC generation
       [not found] <20231121143506.BEB8F3858401@sourceware.org>
@ 2023-11-21 14:38 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2023-11-21 14:38 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Tue, Nov 21, 2023 at 02:35:02PM +0000, Richard Biener wrote:
> For vec_pack_trunc patterns there can be an ambiguity for the
> source mode for BFmode vs HFmode.  The vectorizer checks
> the insns operand mode for this, the following makes forwprop
> do the same.  That of course doesn't help if the target supports
> both conversions.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?
> 
> Thanks,
> Richard.
> 
> 	PR tree-optimization/112623
> 	* tree-ssa-forwprop.cc (simplify_vector_constructor):
> 	Check the source mode of the insn for vector pack/unpacks.
> 
> 	* gcc.target/i386/pr112623.c: New testcase.

LGTM, thanks.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] tree-optimization/112623 - forwprop VEC_PACK_TRUNC generation
@ 2023-11-21 14:35 Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-11-21 14:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

For vec_pack_trunc patterns there can be an ambiguity for the
source mode for BFmode vs HFmode.  The vectorizer checks
the insns operand mode for this, the following makes forwprop
do the same.  That of course doesn't help if the target supports
both conversions.

Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?

Thanks,
Richard.

	PR tree-optimization/112623
	* tree-ssa-forwprop.cc (simplify_vector_constructor):
	Check the source mode of the insn for vector pack/unpacks.

	* gcc.target/i386/pr112623.c: New testcase.
---
 gcc/testsuite/gcc.target/i386/pr112623.c | 11 +++++++++++
 gcc/tree-ssa-forwprop.cc                 | 13 +++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr112623.c

diff --git a/gcc/testsuite/gcc.target/i386/pr112623.c b/gcc/testsuite/gcc.target/i386/pr112623.c
new file mode 100644
index 00000000000..c4ebacec85c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr112623.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -mavx512vl -mavx512fp16" } */
+
+typedef __bf16 __attribute__((__vector_size__ (16))) BF;
+typedef float __attribute__((__vector_size__ (32))) F;
+
+BF
+foo (F f)
+{
+  return __builtin_convertvector (f, BF);
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index d39dfc1065f..0fb21e58138 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-cfgcleanup.h"
 #include "cfganal.h"
 #include "optabs-tree.h"
+#include "insn-config.h"
+#include "recog.h"
 #include "tree-vector-builder.h"
 #include "vec-perm-indices.h"
 #include "internal-fn.h"
@@ -2978,6 +2980,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
 	  /* Only few targets implement direct conversion patterns so try
 	     some simple special cases via VEC_[UN]PACK[_FLOAT]_LO_EXPR.  */
 	  optab optab;
+	  insn_code icode;
 	  tree halfvectype, dblvectype;
 	  enum tree_code unpack_op;
 
@@ -3015,8 +3018,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
 	      && (optab = optab_for_tree_code (unpack_op,
 					       dblvectype,
 					       optab_default))
-	      && (optab_handler (optab, TYPE_MODE (dblvectype))
-		  != CODE_FOR_nothing))
+	      && ((icode = optab_handler (optab, TYPE_MODE (dblvectype)))
+		  != CODE_FOR_nothing)
+	      && (insn_data[icode].operand[0].mode == TYPE_MODE (type)))
 	    {
 	      gimple_seq stmts = NULL;
 	      tree dbl;
@@ -3054,8 +3058,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
 		   && (optab = optab_for_tree_code (VEC_PACK_TRUNC_EXPR,
 						    halfvectype,
 						    optab_default))
-		   && (optab_handler (optab, TYPE_MODE (halfvectype))
-		       != CODE_FOR_nothing))
+		   && ((icode = optab_handler (optab, TYPE_MODE (halfvectype)))
+		       != CODE_FOR_nothing)
+		   && (insn_data[icode].operand[0].mode == TYPE_MODE (type)))
 	    {
 	      gimple_seq stmts = NULL;
 	      tree low = gimple_build (&stmts, BIT_FIELD_REF, halfvectype,
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-21 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20231121143506.BEB8F3858401@sourceware.org>
2023-11-21 14:38 ` [PATCH] tree-optimization/112623 - forwprop VEC_PACK_TRUNC generation Jakub Jelinek
2023-11-21 14:35 Richard Biener

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).