RE: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.

2020-11-04 Thread Richard Biener
On Tue, 3 Nov 2020, Tamar Christina wrote:

> Hi All,
> 
> This patch is a respin of the previous one defining a new helper
> function add_pattern_stmt.
> 
> Ok for master?

OK if the rest is approved.

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
>   * tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static inline.
>   * tree-vect-slp.c (vect_create_new_slp_node): Remove static and only
>   set smts if valid.
>   * tree-vectorizer.c (vec_info::add_pattern_stmt): New.
>   (vec_info::set_vinfo_for_stmt): Optionally enforce read-only.
>   * tree-vectorizer.h (struct _slp_tree): Use new types.
>   (lane_permutation_t, lane_permutation_t): New.
>   (vect_create_new_slp_node, vect_mark_pattern_stmts): New.
> 
> > -Original Message-
> > From: Gcc-patches  On Behalf Of Tamar
> > Christina
> > Sent: Friday, September 25, 2020 3:28 PM
> > To: gcc-patches@gcc.gnu.org
> > Cc: nd ; rguent...@suse.de; o...@ucw.cz
> > Subject: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer
> > helper functions.
> > 
> > Hi All,
> > 
> > This is a small refactoring which exposes some helper functions in the
> > vectorizer so they can be used in other places.
> > 
> > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> > 
> > Ok for master?
> > 
> > Thanks,
> > Tamar
> > 
> > gcc/ChangeLog:
> > 
> > * tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
> > * tree-vect-slp.c (vect_free_slp_tree,
> > vect_build_slp_tree): Remove static.
> > (struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
> > * tree-vectorizer.h (struct bst_traits, bst_traits::hash,
> > bst_traits::equal): ... to here.
> > (vect_mark_pattern_stmts, vect_free_slp_tree,
> > vect_build_slp_tree): Declare.
> > 
> > --
> 

-- 
Richard Biener 
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imend


RE: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.

2020-11-03 Thread Tamar Christina via Gcc-patches
Hi All,

This patch is a respin of the previous one defining a new helper
function add_pattern_stmt.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static inline.
* tree-vect-slp.c (vect_create_new_slp_node): Remove static and only
set smts if valid.
* tree-vectorizer.c (vec_info::add_pattern_stmt): New.
(vec_info::set_vinfo_for_stmt): Optionally enforce read-only.
* tree-vectorizer.h (struct _slp_tree): Use new types.
(lane_permutation_t, lane_permutation_t): New.
(vect_create_new_slp_node, vect_mark_pattern_stmts): New.

> -Original Message-
> From: Gcc-patches  On Behalf Of Tamar
> Christina
> Sent: Friday, September 25, 2020 3:28 PM
> To: gcc-patches@gcc.gnu.org
> Cc: nd ; rguent...@suse.de; o...@ucw.cz
> Subject: [PATCH v2 2/16]middle-end: Refactor and expose some vectorizer
> helper functions.
> 
> Hi All,
> 
> This is a small refactoring which exposes some helper functions in the
> vectorizer so they can be used in other places.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
>   * tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
>   * tree-vect-slp.c (vect_free_slp_tree,
>   vect_build_slp_tree): Remove static.
>   (struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
>   * tree-vectorizer.h (struct bst_traits, bst_traits::hash,
>   bst_traits::equal): ... to here.
>   (vect_mark_pattern_stmts, vect_free_slp_tree,
>   vect_build_slp_tree): Declare.
> 
> --
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index ac56acebe016058cbbc9599cef348ec4211c19d6..32b272ac443cac6bbaf2695c81078a9c8c2a656d 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5216,7 +5216,7 @@ const unsigned int NUM_PATTERNS = ARRAY_SIZE (vect_vect_recog_func_ptrs);
 
 /* Mark statements that are involved in a pattern.  */
 
-static inline void
+void
 vect_mark_pattern_stmts (vec_info *vinfo,
 			 stmt_vec_info orig_stmt_info, gimple *pattern_stmt,
  tree pattern_vectype)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index e97fbe897a76008d50ee94c3b1b009344cc37d4a..30036ec84c74a0e428cc661eacf565224047f9e0 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -148,15 +148,18 @@ vect_free_slp_instance (slp_instance instance)
 
 /* Create an SLP node for SCALAR_STMTS.  */
 
-static slp_tree
+slp_tree
 vect_create_new_slp_node (slp_tree node,
 			  vec scalar_stmts, unsigned nops)
 {
   SLP_TREE_SCALAR_STMTS (node) = scalar_stmts;
   SLP_TREE_CHILDREN (node).create (nops);
   SLP_TREE_DEF_TYPE (node) = vect_internal_def;
-  SLP_TREE_REPRESENTATIVE (node) = scalar_stmts[0];
-  SLP_TREE_LANES (node) = scalar_stmts.length ();
+  if (scalar_stmts.exists ())
+{
+  SLP_TREE_REPRESENTATIVE (node) = scalar_stmts[0];
+  SLP_TREE_LANES (node) = scalar_stmts.length ();
+}
   return node;
 }
 
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index fbf5291cf065f3944040937db92d3997acd45f23..4bd454cfb185d7036843fc7140b073f525b2ec6a 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -115,6 +115,8 @@ typedef hash_map > lane_permutation_t;
+typedef vec load_permutation_t;
 
 extern object_allocator<_slp_tree> *slp_tree_pool;
 
@@ -137,11 +139,11 @@ struct _slp_tree {
 
   /* Load permutation relative to the stores, NULL if there is no
  permutation.  */
-  vec load_permutation;
+  load_permutation_t load_permutation;
   /* Lane permutation of the operands scalar lanes encoded as pairs
  of { operand number, lane number }.  The number of elements
  denotes the number of output lanes.  */
-  vec > lane_permutation;
+  lane_permutation_t lane_permutation;
 
   tree vectype;
   /* Vectorized stmt/s.  */
@@ -348,6 +350,7 @@ public:
   ~vec_info ();
 
   stmt_vec_info add_stmt (gimple *);
+  stmt_vec_info add_pattern_stmt (gimple *, stmt_vec_info);
   stmt_vec_info lookup_stmt (gimple *);
   stmt_vec_info lookup_def (tree);
   stmt_vec_info lookup_single_use (tree);
@@ -393,7 +396,7 @@ public:
 
 private:
   stmt_vec_info new_stmt_vec_info (gimple *stmt);
-  void set_vinfo_for_stmt (gimple *, stmt_vec_info);
+  void set_vinfo_for_stmt (gimple *, stmt_vec_info, bool = true);
   void free_stmt_vec_infos ();
   void free_stmt_vec_info (stmt_vec_info);
 };
@@ -1975,8 +1978,12 @@ extern void duplicate_and_interleave (vec_info *, gimple_seq *, tree,
   vec, unsigned int, vec &);
 extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
 extern bool vect_update_shared_vectype (stmt_vec_info, tree);
+extern slp_tree vect_create_new_slp_node (vec, unsigned);
 
 /* In tree-vect-patterns.c.  */
+extern void
+vect_mark_pat

[PATCH v2 2/16]middle-end: Refactor and expose some vectorizer helper functions.

2020-09-25 Thread Tamar Christina
Hi All,

This is a small refactoring which exposes some helper functions in the
vectorizer so they can be used in other places.

Bootstrapped Regtested on aarch64-none-linux-gnu and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

* tree-vect-patterns.c (vect_mark_pattern_stmts): Remove static.
* tree-vect-slp.c (vect_free_slp_tree,
vect_build_slp_tree): Remove static.
(struct bst_traits, bst_traits::hash, bst_traits::equal): Move...
* tree-vectorizer.h (struct bst_traits, bst_traits::hash,
bst_traits::equal): ... to here.
(vect_mark_pattern_stmts, vect_free_slp_tree,
vect_build_slp_tree): Declare.

-- 
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index db45740da3cba14a3552f9446651e8f289187fbb..3bacd5c827e1a6436c5916022c04e0d6594c316a 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -5169,7 +5169,7 @@ const unsigned int NUM_PATTERNS = ARRAY_SIZE (vect_vect_recog_func_ptrs);
 
 /* Mark statements that are involved in a pattern.  */
 
-static inline void
+void
 vect_mark_pattern_stmts (vec_info *vinfo,
 			 stmt_vec_info orig_stmt_info, gimple *pattern_stmt,
  tree pattern_vectype)
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index bf8ea4326597f4211d2772e9db60aa69285b5998..01189d44d892fc42b132bbb7de1c471df45518ae 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -86,7 +86,7 @@ _slp_tree::~_slp_tree ()
 
 /* Recursively free the memory allocated for the SLP tree rooted at NODE.  */
 
-static void
+void
 vect_free_slp_tree (slp_tree node)
 {
   int i;
@@ -1120,45 +1120,6 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap,
   return true;
 }
 
-/* Traits for the hash_set to record failed SLP builds for a stmt set.
-   Note we never remove apart from at destruction time so we do not
-   need a special value for deleted that differs from empty.  */
-struct bst_traits
-{
-  typedef vec  value_type;
-  typedef vec  compare_type;
-  static inline hashval_t hash (value_type);
-  static inline bool equal (value_type existing, value_type candidate);
-  static inline bool is_empty (value_type x) { return !x.exists (); }
-  static inline bool is_deleted (value_type x) { return !x.exists (); }
-  static const bool empty_zero_p = true;
-  static inline void mark_empty (value_type ) { x.release (); }
-  static inline void mark_deleted (value_type ) { x.release (); }
-  static inline void remove (value_type ) { x.release (); }
-};
-inline hashval_t
-bst_traits::hash (value_type x)
-{
-  inchash::hash h;
-  for (unsigned i = 0; i < x.length (); ++i)
-h.add_int (gimple_uid (x[i]->stmt));
-  return h.end ();
-}
-inline bool
-bst_traits::equal (value_type existing, value_type candidate)
-{
-  if (existing.length () != candidate.length ())
-return false;
-  for (unsigned i = 0; i < existing.length (); ++i)
-if (existing[i] != candidate[i])
-  return false;
-  return true;
-}
-
-typedef hash_map , slp_tree,
-		  simple_hashmap_traits  >
-  scalar_stmts_to_slp_tree_map_t;
-
 static slp_tree
 vect_build_slp_tree_2 (vec_info *vinfo,
 		   vec stmts, unsigned int group_size,
@@ -1166,7 +1127,7 @@ vect_build_slp_tree_2 (vec_info *vinfo,
 		   bool *matches, unsigned *npermutes, unsigned *tree_size,
 		   scalar_stmts_to_slp_tree_map_t *bst_map);
 
-static slp_tree
+slp_tree
 vect_build_slp_tree (vec_info *vinfo,
 		 vec stmts, unsigned int group_size,
 		 poly_uint64 *max_nunits,
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 2ebcf9f9926ec7175f28391f172800499bbc59db..79926f1a43534635ddca85556a928e364022c40a 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2047,6 +2047,9 @@ extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
 extern bool vect_update_shared_vectype (stmt_vec_info, tree);
 
 /* In tree-vect-patterns.c.  */
+extern void
+vect_mark_pattern_stmts (vec_info *, stmt_vec_info, gimple *, tree);
+
 /* Pattern recognition functions.
Additional pattern recognition functions can (and will) be added
in the future.  */
@@ -2058,4 +2061,51 @@ void vect_free_loop_info_assumptions (class loop *);
 gimple *vect_loop_vectorized_call (class loop *, gcond **cond = NULL);
 bool vect_stmt_dominates_stmt_p (gimple *, gimple *);
 
+/* Traits for the hash_set to record failed SLP builds for a stmt set.
+   Note we never remove apart from at destruction time so we do not
+   need a special value for deleted that differs from empty.  */
+struct bst_traits
+{
+  typedef vec  value_type;
+  typedef vec  compare_type;
+  static inline hashval_t hash (value_type);
+  static inline bool equal (value_type existing, value_type candidate);
+  static inline bool is_empty (value_type x) { return !x.exists (); }
+  static inline bool is_deleted (value_type x) { return !x.exists (); }
+  static const bool empty_zero_p = true;
+  static inline void mark_empty (value_type ) {