[PATCH] Fix a slp leak caused by vec.h conversion (PR middle-end/56461)

2013-02-28 Thread Jakub Jelinek
Hi!

This is small, but quite common memory leak in slp vectorization.
vec_alloc (vec_defs, number_of_vects);
on vl_ptr-ish vectree *vec_defs; first calls new on the vectree
(i.e. allocates sizeof (void *) bytes), and then actually creates vector
pointed to by that.  Later on we copy the content of what it points to,
but don't actually free the void * sized allocation.
Fixed by changing the vector to be actually vecvectree  *, which also
simplifies the callers.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-02-28  Jakub Jelinek  ja...@redhat.com

PR middle-end/56461
* tree-vectorizer.h (vect_get_slp_defs): Change 3rd argument
type to vecvectree  *.
* tree-vect-slp.c (vect_get_slp_defs): Likewise.  Change vec_defs
to be vectree instead of vectree *, set vec_defs
to vNULL and call vec_defs.create (number_of_vects), adjust other
uses of vec_defs.
* tree-vect-stmts.c (vect_get_vec_defs, vectorizable_call,
vectorizable_condition): Adjust vect_get_slp_defs callers.

--- gcc/tree-vectorizer.h.jj2013-02-05 16:45:40.0 +0100
+++ gcc/tree-vectorizer.h   2013-02-28 14:17:45.276135327 +0100
@@ -978,7 +978,7 @@ extern bool vect_analyze_slp (loop_vec_i
 extern bool vect_make_slp_decision (loop_vec_info);
 extern void vect_detect_hybrid_slp (loop_vec_info);
 extern void vect_get_slp_defs (vectree , slp_tree,
-  vecslp_void_p *, int);
+  vecvectree  *, int);
 
 extern LOC find_bb_location (basic_block);
 extern bb_vec_info vect_slp_analyze_bb (basic_block);
--- gcc/tree-vect-slp.c.jj  2013-01-31 18:28:54.0 +0100
+++ gcc/tree-vect-slp.c 2013-02-28 14:18:48.339791016 +0100
@@ -2614,14 +2614,14 @@ vect_get_slp_vect_defs (slp_tree slp_nod
 
 void
 vect_get_slp_defs (vectree ops, slp_tree slp_node,
-   vecslp_void_p *vec_oprnds, int reduc_index)
+  vecvectree  *vec_oprnds, int reduc_index)
 {
   gimple first_stmt;
   int number_of_vects = 0, i;
   unsigned int child_index = 0;
   HOST_WIDE_INT lhs_size_unit, rhs_size_unit;
   slp_tree child = NULL;
-  vectree *vec_defs;
+  vectree vec_defs;
   tree oprnd;
   bool vectorized_defs;
 
@@ -2676,19 +2676,20 @@ vect_get_slp_defs (vectree ops, slp_tr
 }
 
   /* Allocate memory for vectorized defs.  */
-  vec_alloc (vec_defs, number_of_vects);
+  vec_defs = vNULL;
+  vec_defs.create (number_of_vects);
 
   /* For reduction defs we call vect_get_constant_vectors (), since we are
  looking for initial loop invariant values.  */
   if (vectorized_defs  reduc_index == -1)
 /* The defs are already vectorized.  */
-vect_get_slp_vect_defs (child, vec_defs);
+   vect_get_slp_vect_defs (child, vec_defs);
   else
 /* Build vectors from scalar defs.  */
-vect_get_constant_vectors (oprnd, slp_node, vec_defs, i,
+   vect_get_constant_vectors (oprnd, slp_node, vec_defs, i,
number_of_vects, reduc_index);
 
-  vec_oprnds-quick_push ((slp_void_p) vec_defs);
+  vec_oprnds-quick_push (vec_defs);
 
   /* For reductions, we only need initial values.  */
   if (reduc_index != -1)
--- gcc/tree-vect-stmts.c.jj2013-02-26 10:58:16.0 +0100
+++ gcc/tree-vect-stmts.c   2013-02-28 14:23:38.181910467 +0100
@@ -1583,7 +1583,7 @@ vect_get_vec_defs (tree op0, tree op1, g
   int nops = (op1 == NULL_TREE) ? 1 : 2;
   vectree ops;
   ops.create (nops);
-  vecslp_void_p vec_defs;
+  vecvectree  vec_defs;
   vec_defs.create (nops);
 
   ops.quick_push (op0);
@@ -1592,9 +1592,9 @@ vect_get_vec_defs (tree op0, tree op1, g
 
   vect_get_slp_defs (ops, slp_node, vec_defs, reduc_index);
 
-  *vec_oprnds0 = *((vectree *) vec_defs[0]);
+  *vec_oprnds0 = vec_defs[0];
   if (op1)
-*vec_oprnds1 = *((vectree *) vec_defs[1]);
+   *vec_oprnds1 = vec_defs[1];
 
   ops.release ();
   vec_defs.release ();
@@ -1882,14 +1882,14 @@ vectorizable_call (gimple stmt, gimple_s
 
  if (slp_node)
{
- vecslp_void_p vec_defs;
+ vecvectree  vec_defs;
  vec_defs.create (nargs);
  vectree vec_oprnds0;
 
  for (i = 0; i  nargs; i++)
vargs.quick_push (gimple_call_arg (stmt, i));
  vect_get_slp_defs (vargs, slp_node, vec_defs, -1);
- vec_oprnds0 = *((vectree *) vec_defs[0]);
+ vec_oprnds0 = vec_defs[0];
 
  /* Arguments are ready.  Create the new vector stmt.  */
  FOR_EACH_VEC_ELT (vec_oprnds0, i, vec_oprnd0)
@@ -1897,7 +1897,7 @@ vectorizable_call (gimple stmt, gimple_s
  size_t k;
  for (k = 0; k  nargs; k++)
{
- vectree vec_oprndsk = *((vectree *) vec_defs[k]);
+ vectree vec_oprndsk = 

Re: [PATCH] Fix a slp leak caused by vec.h conversion (PR middle-end/56461)

2013-02-28 Thread Diego Novillo
On Thu, Feb 28, 2013 at 3:06 PM, Jakub Jelinek ja...@redhat.com wrote:
 Hi!

 This is small, but quite common memory leak in slp vectorization.
 vec_alloc (vec_defs, number_of_vects);
 on vl_ptr-ish vectree *vec_defs; first calls new on the vectree
 (i.e. allocates sizeof (void *) bytes), and then actually creates vector
 pointed to by that.  Later on we copy the content of what it points to,
 but don't actually free the void * sized allocation.
 Fixed by changing the vector to be actually vecvectree  *, which also
 simplifies the callers.

 Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

 2013-02-28  Jakub Jelinek  ja...@redhat.com

 PR middle-end/56461
 * tree-vectorizer.h (vect_get_slp_defs): Change 3rd argument
 type to vecvectree  *.
 * tree-vect-slp.c (vect_get_slp_defs): Likewise.  Change vec_defs
 to be vectree instead of vectree *, set vec_defs
 to vNULL and call vec_defs.create (number_of_vects), adjust other
 uses of vec_defs.
 * tree-vect-stmts.c (vect_get_vec_defs, vectorizable_call,
 vectorizable_condition): Adjust vect_get_slp_defs callers.

OK.


Diego.