public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@linaro.org>
To: gcc-patches@gcc.gnu.org
Subject: [08/13] Add a vec_perm_indices_to_tree helper function
Date: Sat, 09 Dec 2017 23:20:00 -0000	[thread overview]
Message-ID: <87h8szlc89.fsf@linaro.org> (raw)
In-Reply-To: <87indfmrgt.fsf@linaro.org> (Richard Sandiford's message of "Sat,	09 Dec 2017 23:06:26 +0000")

This patch adds a function for creating a VECTOR_CST from a
vec_perm_indices, operating directly on the encoding.


2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* vec-perm-indices.h (vec_perm_indices_to_tree): Declare.
	* vec-perm-indices.c (vec_perm_indices_to_tree): New function.
	* tree-ssa-forwprop.c (simplify_vector_constructor): Use it.
	* tree-vect-slp.c (vect_transform_slp_perm_load): Likewise.
	* tree-vect-stmts.c (vectorizable_bswap): Likewise.
	(vect_gen_perm_mask_any): Likewise.

Index: gcc/vec-perm-indices.h
===================================================================
--- gcc/vec-perm-indices.h	2017-12-09 22:48:47.548825399 +0000
+++ gcc/vec-perm-indices.h	2017-12-09 22:48:50.361942571 +0000
@@ -73,6 +73,7 @@ typedef int_vector_builder<HOST_WIDE_INT
 };
 
 bool tree_to_vec_perm_builder (vec_perm_builder *, tree);
+tree vec_perm_indices_to_tree (tree, const vec_perm_indices &);
 rtx vec_perm_indices_to_rtx (machine_mode, const vec_perm_indices &);
 
 inline
Index: gcc/vec-perm-indices.c
===================================================================
--- gcc/vec-perm-indices.c	2017-12-09 22:48:47.548825399 +0000
+++ gcc/vec-perm-indices.c	2017-12-09 22:48:50.360942531 +0000
@@ -152,6 +152,20 @@ tree_to_vec_perm_builder (vec_perm_build
   return true;
 }
 
+/* Return a VECTOR_CST of type TYPE for the permutation vector in INDICES.  */
+
+tree
+vec_perm_indices_to_tree (tree type, const vec_perm_indices &indices)
+{
+  gcc_assert (TYPE_VECTOR_SUBPARTS (type) == indices.length ());
+  tree_vector_builder sel (type, indices.encoding ().npatterns (),
+			   indices.encoding ().nelts_per_pattern ());
+  unsigned int encoded_nelts = sel.encoded_nelts ();
+  for (unsigned int i = 0; i < encoded_nelts; i++)
+    sel.quick_push (build_int_cst (TREE_TYPE (type), indices[i]));
+  return sel.build ();
+}
+
 /* Return a CONST_VECTOR of mode MODE that contains the elements of
    INDICES.  */
 
Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c	2017-12-09 22:48:47.546825312 +0000
+++ gcc/tree-ssa-forwprop.c	2017-12-09 22:48:50.359942492 +0000
@@ -2119,10 +2119,7 @@ simplify_vector_constructor (gimple_stmt
 	  || GET_MODE_SIZE (TYPE_MODE (mask_type))
 	     != GET_MODE_SIZE (TYPE_MODE (type)))
 	return false;
-      tree_vector_builder mask_elts (mask_type, nelts, 1);
-      for (i = 0; i < nelts; i++)
-	mask_elts.quick_push (build_int_cst (TREE_TYPE (mask_type), sel[i]));
-      op2 = mask_elts.build ();
+      op2 = vec_perm_indices_to_tree (mask_type, indices);
       if (conv_code == ERROR_MARK)
 	gimple_assign_set_rhs_with_ops (gsi, VEC_PERM_EXPR, orig, orig, op2);
       else
Index: gcc/tree-vect-slp.c
===================================================================
--- gcc/tree-vect-slp.c	2017-12-09 22:48:47.547825355 +0000
+++ gcc/tree-vect-slp.c	2017-12-09 22:48:50.359942492 +0000
@@ -3675,13 +3675,7 @@ vect_transform_slp_perm_load (slp_tree n
 		  tree mask_vec = NULL_TREE;
 		  
 		  if (! noop_p)
-		    {
-		      tree_vector_builder mask_elts (mask_type, nunits, 1);
-		      for (int l = 0; l < nunits; ++l)
-			mask_elts.quick_push (build_int_cst (mask_element_type,
-							     mask[l]));
-		      mask_vec = mask_elts.build ();
-		    }
+		    mask_vec = vec_perm_indices_to_tree (mask_type, indices);
 
 		  if (second_vec_index == -1)
 		    second_vec_index = first_vec_index;
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2017-12-09 22:48:47.548825399 +0000
+++ gcc/tree-vect-stmts.c	2017-12-09 22:48:50.360942531 +0000
@@ -2529,10 +2529,7 @@ vectorizable_bswap (gimple *stmt, gimple
       return true;
     }
 
-  tree_vector_builder telts (char_vectype, num_bytes, 1);
-  for (unsigned i = 0; i < num_bytes; ++i)
-    telts.quick_push (build_int_cst (char_type_node, elts[i]));
-  tree bswap_vconst = telts.build ();
+  tree bswap_vconst = vec_perm_indices_to_tree (char_vectype, indices);
 
   /* Transform.  */
   vec<tree> vec_oprnds = vNULL;
@@ -6521,17 +6518,10 @@ vect_gen_perm_mask_any (tree vectype, co
 {
   tree mask_elt_type, mask_type;
 
-  unsigned int nunits = sel.length ();
-  gcc_checking_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));
-
   mask_elt_type = lang_hooks.types.type_for_mode
     (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);
   mask_type = get_vectype_for_scalar_type (mask_elt_type);
-
-  tree_vector_builder mask_elts (mask_type, nunits, 1);
-  for (unsigned int i = 0; i < nunits; ++i)
-    mask_elts.quick_push (build_int_cst (mask_elt_type, sel[i]));
-  return mask_elts.build ();
+  return vec_perm_indices_to_tree (mask_type, sel);
 }
 
 /* Checked version of vect_gen_perm_mask_any.  Asserts can_vec_perm_const_p,

  parent reply	other threads:[~2017-12-09 23:20 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09 23:06 [00/13] Make VEC_PERM_EXPR work for variable-length vectors Richard Sandiford
2017-12-09 23:08 ` [01/13] Add a qimode_for_vec_perm helper function Richard Sandiford
2017-12-18 13:34   ` Richard Biener
2017-12-09 23:09 ` [02/13] Pass vec_perm_indices by reference Richard Sandiford
2017-12-12 14:23   ` Richard Biener
2017-12-09 23:11 ` [03/13] Split can_vec_perm_p into can_vec_perm_{var,const}_p Richard Sandiford
2017-12-12 14:25   ` Richard Biener
2017-12-09 23:13 ` [04/13] Refactor expand_vec_perm Richard Sandiford
2017-12-12 15:17   ` Richard Biener
2017-12-09 23:17 ` [05/13] Remove vec_perm_const optab Richard Sandiford
2017-12-12 15:26   ` Richard Biener
2017-12-20 13:42     ` Richard Sandiford
2017-12-09 23:18 ` [06/13] Check whether a vector of QIs can store all indices Richard Sandiford
2017-12-12 15:27   ` Richard Biener
2017-12-09 23:20 ` [07/13] Make vec_perm_indices use new vector encoding Richard Sandiford
2017-12-12 15:32   ` Richard Biener
2017-12-12 15:47     ` Richard Sandiford
2017-12-14 10:37       ` Richard Biener
2017-12-20 13:48         ` Richard Sandiford
2018-01-02 13:15           ` Richard Biener
2018-01-02 18:30             ` Richard Sandiford
2017-12-09 23:20 ` Richard Sandiford [this message]
2017-12-18 13:34   ` [08/13] Add a vec_perm_indices_to_tree helper function Richard Biener
2017-12-09 23:21 ` [09/13] Use explicit encodings for simple permutes Richard Sandiford
2017-12-19 20:37   ` Richard Sandiford
2018-01-02 13:07   ` Richard Biener
2017-12-09 23:23 ` [10/13] Rework VEC_PERM_EXPR folding Richard Sandiford
2017-12-09 23:24   ` [11/13] Use vec_perm_builder::series_p in shift_amt_for_vec_perm_mask Richard Sandiford
2017-12-19 20:37     ` Richard Sandiford
2018-01-02 13:08     ` Richard Biener
2017-12-09 23:25   ` [12/13] Use ssizetype selectors for autovectorised VEC_PERM_EXPRs Richard Sandiford
2017-12-19 20:37     ` Richard Sandiford
2018-01-02 13:09     ` Richard Biener
2017-12-19 20:37   ` [10/13] Rework VEC_PERM_EXPR folding Richard Sandiford
2018-01-02 13:08   ` Richard Biener
2017-12-09 23:27 ` [13/13] [AArch64] Use vec_perm_indices helper routines Richard Sandiford
2017-12-19 20:37   ` Richard Sandiford
2018-01-04 11:28     ` Richard Sandiford
2018-01-09 12:18       ` James Greenhalgh
2018-01-09 16:24         ` RFA: Expand vec_perm_indices::series_p comment Richard Sandiford
2018-01-29 20:56           ` Ping: " Richard Sandiford
2018-01-30  7:20             ` Jeff Law
2017-12-12 14:12 ` [00/13] Make VEC_PERM_EXPR work for variable-length vectors Richard Biener
2017-12-12 15:32   ` Richard Sandiford
2017-12-12 15:38     ` Richard Biener
2017-12-12 15:57       ` Richard Sandiford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h8szlc89.fsf@linaro.org \
    --to=richard.sandiford@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).