From a154b43a811a710525c1da93ea4f97c97c9327f9 Mon Sep 17 00:00:00 2001 From: Zdenek Dvorak Date: Tue, 17 Apr 2007 18:42:29 +0200 Subject: re PR rtl-optimization/31360 (RTL loop invariant is not aggressive enough) PR rtl-optimization/31360 * cfgloopanal.c (target_small_cost, target_pres_cost): Removed. (target_reg_cost): New. (init_set_costs): Initialize target_reg_cost. Add comments regarding the rationale of the costs. (global_cost_for_size): Renamed to... (estimate_reg_pressure_cost): ... and simplify. Decrease importance of register pressure. * tree-ssa-loop-ivopts.c (ivopts_global_cost_for_size): Use estimate_reg_pressure_cost. Add number of ivs. (determine_set_costs): Dump target_reg_cost. * loop-invariant.c (gain_for_invariant): Use estimate_reg_pressure_cost. Removed n_inv_uses argument. (best_gain_for_invariant, find_invariants_to_move): Remove n_inv_uses. * cfgloop.h (target_small_cost, target_pres_cost): Removed. (target_reg_cost): Declare. (global_cost_for_size): Declaration removed. (estimate_reg_pressure_cost): Declare. * gcc.dg/loop-7.c: New test. From-SVN: r123919 --- gcc/loop-invariant.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'gcc/loop-invariant.c') diff --git a/gcc/loop-invariant.c b/gcc/loop-invariant.c index 4c6e8bc..304e424 100644 --- a/gcc/loop-invariant.c +++ b/gcc/loop-invariant.c @@ -983,37 +983,34 @@ get_inv_cost (struct invariant *inv, int *comp_cost, unsigned *regs_needed) } /* Calculates gain for eliminating invariant INV. REGS_USED is the number - of registers used in the loop, N_INV_USES is the number of uses of - invariants, NEW_REGS is the number of new variables already added due to - the invariant motion. The number of registers needed for it is stored in - *REGS_NEEDED. */ + of registers used in the loop, NEW_REGS is the number of new variables + already added due to the invariant motion. The number of registers needed + for it is stored in *REGS_NEEDED. */ static int gain_for_invariant (struct invariant *inv, unsigned *regs_needed, - unsigned new_regs, unsigned regs_used, unsigned n_inv_uses) + unsigned new_regs, unsigned regs_used) { int comp_cost, size_cost; get_inv_cost (inv, &comp_cost, regs_needed); actual_stamp++; - size_cost = (global_cost_for_size (new_regs + *regs_needed, - regs_used, n_inv_uses) - - global_cost_for_size (new_regs, regs_used, n_inv_uses)); + size_cost = (estimate_reg_pressure_cost (new_regs + *regs_needed, regs_used) + - estimate_reg_pressure_cost (new_regs, regs_used)); return comp_cost - size_cost; } /* Finds invariant with best gain for moving. Returns the gain, stores the invariant in *BEST and number of registers needed for it to - *REGS_NEEDED. REGS_USED is the number of registers used in - the loop, N_INV_USES is the number of uses of invariants. NEW_REGS - is the number of new variables already added due to invariant motion. */ + *REGS_NEEDED. REGS_USED is the number of registers used in the loop. + NEW_REGS is the number of new variables already added due to invariant + motion. */ static int best_gain_for_invariant (struct invariant **best, unsigned *regs_needed, - unsigned new_regs, unsigned regs_used, - unsigned n_inv_uses) + unsigned new_regs, unsigned regs_used) { struct invariant *inv; int gain = 0, again; @@ -1028,8 +1025,7 @@ best_gain_for_invariant (struct invariant **best, unsigned *regs_needed, if (inv->eqto != inv->invno) continue; - again = gain_for_invariant (inv, &aregs_needed, - new_regs, regs_used, n_inv_uses); + again = gain_for_invariant (inv, &aregs_needed, new_regs, regs_used); if (again > gain) { gain = again; @@ -1070,19 +1066,16 @@ set_move_mark (unsigned invno) static void find_invariants_to_move (void) { - unsigned i, regs_used, n_inv_uses, regs_needed = 0, new_regs; + unsigned i, regs_used, regs_needed = 0, new_regs; struct invariant *inv = NULL; unsigned int n_regs = DF_REG_SIZE (df); if (!VEC_length (invariant_p, invariants)) return; - /* Now something slightly more involved. First estimate the number of used - registers. */ - n_inv_uses = 0; - - /* We do not really do a good job in this estimation; put some initial bound - here to stand for induction variables etc. that we do not detect. */ + /* We do not really do a good job in estimating number of registers used; + we put some initial bound here to stand for induction variables etc. + that we do not detect. */ regs_used = 2; for (i = 0; i < n_regs; i++) @@ -1094,15 +1087,8 @@ find_invariants_to_move (void) } } - for (i = 0; VEC_iterate (invariant_p, invariants, i, inv); i++) - { - if (inv->def) - n_inv_uses += inv->def->n_uses; - } - new_regs = 0; - while (best_gain_for_invariant (&inv, ®s_needed, - new_regs, regs_used, n_inv_uses) > 0) + while (best_gain_for_invariant (&inv, ®s_needed, new_regs, regs_used) > 0) { set_move_mark (inv->invno); new_regs += regs_needed; -- cgit v1.1