Commit f2fa288f by Richard Henderson Committed by Richard Henderson

cse.c (notreg_cost): New argument outer.

        * cse.c (notreg_cost): New argument outer.
        (COST): Pass in SET to notreg_cost
        (COST_IN): New.
        (fold_rtx): Use COST_IN.  Prefer constants when costs
        are the same.

From-SVN: r36671
parent 99eaf8d4
2000-09-29 Richard Henderson <rth@cygnus.com>
* cse.c (notreg_cost): New argument outer.
(COST): Pass in SET to notreg_cost
(COST_IN): New.
(fold_rtx): Use COST_IN. Prefer constants when costs
are the same.
2000-09-29 David Edelsohn <edelsohn@gnu.org> 2000-09-29 David Edelsohn <edelsohn@gnu.org>
* fixinc/inclhack.def (broken_cabs): Generalize regex. * fixinc/inclhack.def (broken_cabs): Generalize regex.
......
...@@ -502,7 +502,8 @@ struct table_elt ...@@ -502,7 +502,8 @@ struct table_elt
|| ((N) < FIRST_PSEUDO_REGISTER \ || ((N) < FIRST_PSEUDO_REGISTER \
&& FIXED_REGNO_P (N) && REGNO_REG_CLASS (N) != NO_REGS)) && FIXED_REGNO_P (N) && REGNO_REG_CLASS (N) != NO_REGS))
#define COST(X) (GET_CODE (X) == REG ? 0 : notreg_cost (X)) #define COST(X) (GET_CODE (X) == REG ? 0 : notreg_cost (X, SET))
#define COST_IN(X,OUTER) (GET_CODE (X) == REG ? 0 : notreg_cost (X, OUTER))
/* Get the info associated with register N. */ /* Get the info associated with register N. */
...@@ -636,7 +637,7 @@ struct cse_basic_block_data ...@@ -636,7 +637,7 @@ struct cse_basic_block_data
|| XEXP (X, 0) == virtual_outgoing_args_rtx)) \ || XEXP (X, 0) == virtual_outgoing_args_rtx)) \
|| GET_CODE (X) == ADDRESSOF) || GET_CODE (X) == ADDRESSOF)
static int notreg_cost PARAMS ((rtx)); static int notreg_cost PARAMS ((rtx, enum rtx_code));
static int approx_reg_cost_1 PARAMS ((rtx *, void *)); static int approx_reg_cost_1 PARAMS ((rtx *, void *));
static int approx_reg_cost PARAMS ((rtx)); static int approx_reg_cost PARAMS ((rtx));
static int preferrable PARAMS ((int, int, int, int)); static int preferrable PARAMS ((int, int, int, int));
...@@ -800,8 +801,9 @@ preferrable (cost_a, regcost_a, cost_b, regcost_b) ...@@ -800,8 +801,9 @@ preferrable (cost_a, regcost_a, cost_b, regcost_b)
from COST macro to keep it simple. */ from COST macro to keep it simple. */
static int static int
notreg_cost (x) notreg_cost (x, outer)
rtx x; rtx x;
enum rtx_code outer;
{ {
return ((GET_CODE (x) == SUBREG return ((GET_CODE (x) == SUBREG
&& GET_CODE (SUBREG_REG (x)) == REG && GET_CODE (SUBREG_REG (x)) == REG
...@@ -813,7 +815,7 @@ notreg_cost (x) ...@@ -813,7 +815,7 @@ notreg_cost (x)
&& TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (GET_MODE (x)), && TRULY_NOOP_TRUNCATION (GET_MODE_BITSIZE (GET_MODE (x)),
GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))))) GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x)))))
? 0 ? 0
: rtx_cost (x, SET) * 2); : rtx_cost (x, outer) * 2);
} }
/* Return an estimate of the cost of computing rtx X. /* Return an estimate of the cost of computing rtx X.
...@@ -3752,7 +3754,7 @@ fold_rtx (x, insn) ...@@ -3752,7 +3754,7 @@ fold_rtx (x, insn)
/* Pick the least expensive of the folded argument and an /* Pick the least expensive of the folded argument and an
equivalent constant argument. */ equivalent constant argument. */
if (const_arg == 0 || const_arg == folded_arg if (const_arg == 0 || const_arg == folded_arg
|| COST (const_arg) > COST (folded_arg)) || COST_IN (const_arg, code) > COST_IN (folded_arg, code))
cheap_arg = folded_arg, expensive_arg = const_arg; cheap_arg = folded_arg, expensive_arg = const_arg;
else else
cheap_arg = const_arg, expensive_arg = folded_arg; cheap_arg = const_arg, expensive_arg = folded_arg;
...@@ -3772,12 +3774,21 @@ fold_rtx (x, insn) ...@@ -3772,12 +3774,21 @@ fold_rtx (x, insn)
copied = 1; copied = 1;
} }
replacements[0] = cheap_arg, replacements[1] = expensive_arg; /* Order the replacements from cheapest to most expensive. */
for (j = 0; replacements[0] = cheap_arg;
j < 2 && replacements[j] replacements[1] = expensive_arg;
&& COST (replacements[j]) < COST (XEXP (x, i));
j++) for (j = 0; j < 2 && replacements[j]; j++)
{ {
int old_cost = COST_IN (XEXP (x, i), code);
int new_cost = COST_IN (replacements[j], code);
/* Stop if what existed before was cheaper. Prefer constants
in the case of a tie. */
if (new_cost > old_cost
|| (new_cost == old_cost && CONSTANT_P (XEXP (x, i))))
break;
if (validate_change (insn, &XEXP (x, i), replacements[j], 0)) if (validate_change (insn, &XEXP (x, i), replacements[j], 0))
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment