Patchwork Fix vectorizable_store memory leaks (PR middle-end/56461)

login
register
mail settings
Submitter Jakub Jelinek
Date March 1, 2013, 8:23 p.m.
Message ID <20130301202303.GK12913@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/224450/
State New
Headers show

Comments

Jakub Jelinek - March 1, 2013, 8:23 p.m.
Hi!

The first two hunks are similar issue to what I've posted for
vect_permute_load_chain two days ago, the remaining issue is that
if ncopies > 1, we'd leak the result_chain vector too.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2013-03-01  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/56461
	* tree-vect-data-refs.c (vect_permute_store_chain): Avoid using copy
	method on dr_chain and result_chain.
	* tree-vect-stmts.c (vectorizable_store): Only call
	result_chain.create if j == 0.


	Jakub
Jeff Law - March 1, 2013, 10:41 p.m.
On 03/01/2013 01:23 PM, Jakub Jelinek wrote:
> Hi!
>
> The first two hunks are similar issue to what I've posted for
> vect_permute_load_chain two days ago, the remaining issue is that
> if ncopies > 1, we'd leak the result_chain vector too.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2013-03-01  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR middle-end/56461
> 	* tree-vect-data-refs.c (vect_permute_store_chain): Avoid using copy
> 	method on dr_chain and result_chain.
> 	* tree-vect-stmts.c (vectorizable_store): Only call
> 	result_chain.create if j == 0.
This is fine.  Please install.  Thanks.

Jeff
Richard Guenther - March 4, 2013, 10 a.m.
On Fri, 1 Mar 2013, Jakub Jelinek wrote:

> Hi!
> 
> The first two hunks are similar issue to what I've posted for
> vect_permute_load_chain two days ago, the remaining issue is that
> if ncopies > 1, we'd leak the result_chain vector too.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

Ok.

Thanks,
Richard.

> 2013-03-01  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/56461
> 	* tree-vect-data-refs.c (vect_permute_store_chain): Avoid using copy
> 	method on dr_chain and result_chain.
> 	* tree-vect-stmts.c (vectorizable_store): Only call
> 	result_chain.create if j == 0.
> 
> --- gcc/tree-vect-data-refs.c.jj	2013-02-27 23:05:57.000000000 +0100
> +++ gcc/tree-vect-data-refs.c	2013-03-01 17:41:12.296992793 +0100
> @@ -4218,7 +4218,9 @@ vect_permute_store_chain (vec<tree> dr_c
>    unsigned int j, nelt = TYPE_VECTOR_SUBPARTS (vectype);
>    unsigned char *sel = XALLOCAVEC (unsigned char, nelt);
>  
> -  *result_chain = dr_chain.copy ();
> +  result_chain->quick_grow (length);
> +  memcpy (result_chain->address (), dr_chain.address (),
> +	  length * sizeof (tree));
>  
>    for (i = 0, n = nelt / 2; i < n; i++)
>      {
> @@ -4259,7 +4261,8 @@ vect_permute_store_chain (vec<tree> dr_c
>  	  vect_finish_stmt_generation (stmt, perm_stmt, gsi);
>  	  (*result_chain)[2*j+1] = low;
>  	}
> -      dr_chain = result_chain->copy ();
> +      memcpy (dr_chain.address (), result_chain->address (),
> +	      length * sizeof (tree));
>      }
>  }
>  
> --- gcc/tree-vect-stmts.c.jj	2013-03-01 13:33:37.000000000 +0100
> +++ gcc/tree-vect-stmts.c	2013-03-01 17:35:17.146958118 +0100
> @@ -4135,7 +4135,8 @@ vectorizable_store (gimple stmt, gimple_
>  	  new_stmt = NULL;
>  	  if (grouped_store)
>  	    {
> -	      result_chain.create (group_size);
> +	      if (j == 0)
> +		result_chain.create (group_size);
>  	      /* Permute.  */
>  	      vect_permute_store_chain (dr_chain, group_size, stmt, gsi,
>  					&result_chain);
> 
> 	Jakub
> 
>

Patch

--- gcc/tree-vect-data-refs.c.jj	2013-02-27 23:05:57.000000000 +0100
+++ gcc/tree-vect-data-refs.c	2013-03-01 17:41:12.296992793 +0100
@@ -4218,7 +4218,9 @@  vect_permute_store_chain (vec<tree> dr_c
   unsigned int j, nelt = TYPE_VECTOR_SUBPARTS (vectype);
   unsigned char *sel = XALLOCAVEC (unsigned char, nelt);
 
-  *result_chain = dr_chain.copy ();
+  result_chain->quick_grow (length);
+  memcpy (result_chain->address (), dr_chain.address (),
+	  length * sizeof (tree));
 
   for (i = 0, n = nelt / 2; i < n; i++)
     {
@@ -4259,7 +4261,8 @@  vect_permute_store_chain (vec<tree> dr_c
 	  vect_finish_stmt_generation (stmt, perm_stmt, gsi);
 	  (*result_chain)[2*j+1] = low;
 	}
-      dr_chain = result_chain->copy ();
+      memcpy (dr_chain.address (), result_chain->address (),
+	      length * sizeof (tree));
     }
 }
 
--- gcc/tree-vect-stmts.c.jj	2013-03-01 13:33:37.000000000 +0100
+++ gcc/tree-vect-stmts.c	2013-03-01 17:35:17.146958118 +0100
@@ -4135,7 +4135,8 @@  vectorizable_store (gimple stmt, gimple_
 	  new_stmt = NULL;
 	  if (grouped_store)
 	    {
-	      result_chain.create (group_size);
+	      if (j == 0)
+		result_chain.create (group_size);
 	      /* Permute.  */
 	      vect_permute_store_chain (dr_chain, group_size, stmt, gsi,
 					&result_chain);