This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lno] Fix memory leak in ivopts


Hello,

this patch fixes the memory leak in iv optimization and speeds it up so
that it behaves more reasonably (as much as 15% of compiler time can be
thought reasonable.  Working on that); at least it should not prevent
testing of other parts of the loop optimizer as it happened with loop
versioning.

Zdenek

Index: ChangeLog.lno
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/ChangeLog.lno,v
retrieving revision 1.1.2.44
diff -c -3 -p -r1.1.2.44 ChangeLog.lno
*** ChangeLog.lno	30 Jan 2004 08:32:03 -0000	1.1.2.44
--- ChangeLog.lno	30 Jan 2004 14:15:12 -0000
***************
*** 1,5 ****
--- 1,12 ----
  2004-01-29  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
  
+ 	* tree-ssa-loop-ivopts.c (find_optimal_iv_set_1, compute_iv_set_cost):
+ 	Fix memory leak, speed up.
+ 	(tree_ssa_iv_optimize_finalize): Move reseting of DECL_RTL...
+ 	(free_loop_data): ... here.
+ 
+ 2004-01-29  Zdenek Dvorak  <rakdver@atrey.karlin.mff.cuni.cz>
+ 
  	* basic-block.h (FOR_BB_INSNS, FOR_BB_INSNS_REVERSE): New macros.
  	* cfgloop.c (num_loop_branches): New function.
  	* cfgloop.h (struct loop_desc): Add field strange.
Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-loop-ivopts.c,v
retrieving revision 1.1.2.3
diff -c -3 -p -r1.1.2.3 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c	30 Jan 2004 08:32:06 -0000	1.1.2.3
--- tree-ssa-loop-ivopts.c	30 Jan 2004 14:15:13 -0000
*************** compute_iv_set_cost (bitmap set, bitmap 
*** 2672,2677 ****
--- 2672,2678 ----
    struct iv_use *use;
    struct iv_cand *cand;
    unsigned size = 0;
+   bool infty = false;
  
    *cost = 0;
    *delta = 0;
*************** compute_iv_set_cost (bitmap set, bitmap 
*** 2685,2692 ****
  
        if (acost == INFTY)
  	{
! 	  *cost = *delta = INFTY;
! 	  return;
  	}
  
        bitmap_set_bit (used, cand->id);
--- 2686,2693 ----
  
        if (acost == INFTY)
  	{
! 	  infty = true;
! 	  continue;
  	}
  
        bitmap_set_bit (used, cand->id);
*************** compute_iv_set_cost (bitmap set, bitmap 
*** 2695,2700 ****
--- 2696,2707 ----
        *delta += acost - use->best_cost;
      }
  
+   if (infty)
+     {
+       *cost = *delta = INFTY;
+       return;
+     }
+ 
    /* Now add the candidate costs.  */
    EXECUTE_IF_SET_IN_BITMAP (used, 0, i,
      {
*************** find_optimal_iv_set_1 (unsigned iv_num, 
*** 2729,2753 ****
        return;
      }
  
    bitmap_set_bit (actual, iv_num);
    used_cands = BITMAP_XMALLOC ();
    compute_iv_set_cost (actual, used_cands, &cost_with, &delta);
  
!   if (cost_with < *best_cost + delta)
      {
!       if (cost_with == INFTY)
  	find_optimal_iv_set_1 (iv_num + 1, actual, cost_with, best, best_cost);
-       else
- 	{
- 	  if (cost_with < actual_cost
- 	      /* If not all candidates are used, there is no point in trying
- 		 the possibility here.  */
- 	      && bitmap_equal_p (used_cands, actual))
- 	    find_optimal_iv_set_1 (iv_num + 1, actual, cost_with,
- 				   best, best_cost);
- 	}
      }
  
    bitmap_clear_bit (actual, iv_num);
    find_optimal_iv_set_1 (iv_num + 1, actual, actual_cost, best, best_cost);
  }
--- 2736,2762 ----
        return;
      }
  
+   if (tree_dump_file && (tree_dump_flags & TDF_DETAILS))
+     {
+       bitmap_print (tree_dump_file, actual, "Examining set ", "");
+       fprintf (tree_dump_file, " (cost %d)\n", actual_cost);
+     }
+ 
    bitmap_set_bit (actual, iv_num);
    used_cands = BITMAP_XMALLOC ();
    compute_iv_set_cost (actual, used_cands, &cost_with, &delta);
  
!   if (cost_with < *best_cost + delta
!       /* If not all candidates are used, there is no point in trying
! 	 the possibility.  */
!       && bitmap_equal_p (used_cands, actual))
      {
!       if (cost_with == INFTY
! 	  || cost_with < actual_cost)
  	find_optimal_iv_set_1 (iv_num + 1, actual, cost_with, best, best_cost);
      }
  
+   BITMAP_XFREE (used_cands);
    bitmap_clear_bit (actual, iv_num);
    find_optimal_iv_set_1 (iv_num + 1, actual, actual_cost, best, best_cost);
  }
*************** find_optimal_iv_set_1 (unsigned iv_num, 
*** 2758,2764 ****
     
     1) If adding a variable would make the cost grow, it is not worthwhile
        (this is not true under some weird circumstances, but for any
!       practical example it is).
     2) When computing the costs of uses we also compute the minimum cost
        of uses we could reach by choosing the optimal iv as a base for them.
        We use this information to cut the imperspective branches.  */
--- 2767,2773 ----
     
     1) If adding a variable would make the cost grow, it is not worthwhile
        (this is not true under some weird circumstances, but for any
!       practical example it is so).
     2) When computing the costs of uses we also compute the minimum cost
        of uses we could reach by choosing the optimal iv as a base for them.
        We use this information to cut the imperspective branches.  */
*************** free_loop_data (void)
*** 3047,3052 ****
--- 3056,3069 ----
  	      * (highest_ssa_version - old_highest_ssa_version));
      }
  
+   for (i = 0; i < VARRAY_ACTIVE_SIZE (decl_rtl_to_reset); i++)
+     {
+       tree obj = VARRAY_GENERIC_PTR_NOGC (decl_rtl_to_reset, i);
+ 
+       SET_DECL_RTL (obj, NULL_RTX);
+     }
+   VARRAY_POP_ALL (decl_rtl_to_reset);
+   
    old_highest_ssa_version = highest_ssa_version;
  }
  
*************** static void
*** 3057,3063 ****
  tree_ssa_iv_optimize_finalize (struct loops *loops)
  {
    unsigned i;
-   tree obj;
  
    for (i = 1; i < loops->num; i++)
      if (loops->parray[i])
--- 3074,3079 ----
*************** tree_ssa_iv_optimize_finalize (struct lo
*** 3070,3082 ****
    free (ivs);
    free (outermost_usage);
  
-   for (i = 0; i < VARRAY_ACTIVE_SIZE (decl_rtl_to_reset); i++)
-     {
-       obj = VARRAY_GENERIC_PTR_NOGC (decl_rtl_to_reset, i);
- 
-       SET_DECL_RTL (obj, NULL_RTX);
-     }
-   
    VARRAY_FREE (decl_rtl_to_reset);
    VARRAY_FREE (iv_uses);
    VARRAY_FREE (iv_candidates);
--- 3086,3091 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]