diff mbox

Fix memory leak and wrong invariant dependence computation in IVOPT

Message ID 001701d11126$16e74620$44b5d260$@arm.com
State New
Headers show

Commit Message

Bin Cheng Oct. 28, 2015, 2:12 a.m. UTC
Hi,
When address iv uses grouping was introduced, I also introduced memory leak
and wrong computation of depends_on bitmap.  The intention is to skip
`depends_on' computation for sub address type iv uses.  Unfortunately, the
code is wrong because depends_on is freed in subsequent calls to
get_computation_cost for a grouped iv use.  This results in loss of
depends_on information, as well memory leaks for depends_on bitmap.

I think this is an obvious fix to the issue.  Bootstrap and test on x86_64.
OK?

Thanks,
bin

2015-10-27  Bin Cheng  <bin.cheng@arm.com>

	* tree-ssa-loop-ivopts.c (split_address_cost): Check depends_on.
	(get_computation_cost_at): Ditto.
	(determine_use_iv_cost_address): Pass NULL for arguments depends_on
	and inv_expr_id.

Comments

Richard Biener Oct. 28, 2015, 12:44 p.m. UTC | #1
On Wed, Oct 28, 2015 at 3:12 AM, Bin Cheng <bin.cheng@arm.com> wrote:
> Hi,
> When address iv uses grouping was introduced, I also introduced memory leak
> and wrong computation of depends_on bitmap.  The intention is to skip
> `depends_on' computation for sub address type iv uses.  Unfortunately, the
> code is wrong because depends_on is freed in subsequent calls to
> get_computation_cost for a grouped iv use.  This results in loss of
> depends_on information, as well memory leaks for depends_on bitmap.
>
> I think this is an obvious fix to the issue.  Bootstrap and test on x86_64.
> OK?

Ok.

Richard.

> Thanks,
> bin
>
> 2015-10-27  Bin Cheng  <bin.cheng@arm.com>
>
>         * tree-ssa-loop-ivopts.c (split_address_cost): Check depends_on.
>         (get_computation_cost_at): Ditto.
>         (determine_use_iv_cost_address): Pass NULL for arguments depends_on
>         and inv_expr_id.
>
diff mbox

Patch

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 945d34b..91f7284 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -4328,7 +4328,9 @@  split_address_cost (struct ivopts_data *data,
       *symbol_present = false;
       *var_present = true;
       fd_ivopts_data = data;
-      walk_tree (&addr, find_depends, depends_on, NULL);
+      if (depends_on)
+	walk_tree (&addr, find_depends, depends_on, NULL);
+
       return new_cost (target_spill_cost[data->speed], 0);
     }
 
@@ -4616,7 +4618,8 @@  get_computation_cost_at (struct ivopts_data *data,
 				? TYPE_MODE (TREE_TYPE (*use->op_p))
 				: VOIDmode);
 
-  *depends_on = NULL;
+  if (depends_on)
+    *depends_on = NULL;
 
   /* Only consider real candidates.  */
   if (!cand->iv)
@@ -4908,9 +4911,9 @@  determine_use_iv_cost_address (struct ivopts_data *data,
        sub_use && !infinite_cost_p (cost);
        sub_use = sub_use->next)
     {
-       sub_cost = get_computation_cost (data, sub_use, cand, true, &depends_on,
-					&can_autoinc, &inv_expr_id);
-       cost = add_costs (cost, sub_cost);
+      sub_cost = get_computation_cost (data, sub_use, cand, true, NULL,
+				       &can_autoinc, NULL);
+      cost = add_costs (cost, sub_cost);
     }
 
   set_use_iv_cost (data, use, cand, cost, depends_on, NULL_TREE, ERROR_MARK,