Just what are rtx costs?

Paolo Bonzini bonzini@gnu.org
Wed Aug 17 18:56:00 GMT 2011


On 08/17/2011 07:52 AM, Richard Sandiford wrote:
>    cost = rtx_cost (SET_SRC (set), SET, speed);
>    return cost>  0 ? cost : COSTS_N_INSNS (1);
>
> This ignores SET_DEST (the problem I'm trying to fix).  It also means
> that constants that are slightly more expensive than a register --
> somewhere in the range [0, COSTS_N_INSNS (1)] -- end up seeming
> cheaper than registers.

This can be fixed by doing

   return cost >= COSTS_N_INSNS (1) ? cost : COSTS_N_INSNS (1);

> One approach I'm trying is to make sure that every target that doesn't
> explicitly handle SET does nothing with it.  (Targets that do handle
> SET remain unchanged.)  Then, if we see a SET whose SET_SRC is a
> register, constant, memory or subreg, we give it cost:
>
>      COSTS_N_INSNS (1)
>      + rtx_cost (SET_DEST (x), SET, speed)
>      + rtx_cost (SET_SRC (x), SET, speed)
>
> as now.  In other cases we give it a cost of:
>
>      rtx_cost (SET_DEST (x), SET, speed)
>      + rtx_cost (SET_SRC (x), SET, speed)
>
> But that hardly seems clean either.  Perhaps we should instead make
> the SET_SRC always include the cost of the SET, even for registers,
> constants and the like.  Thoughts?

Similarly, this becomes

   dest_cost = rtx_cost (SET_DEST (x), SET, speed);
   src_cost = MAX (rtx_cost (SET_SRC (x), SET, speed),
                   COSTS_N_INSNS (1));
   return dest_cost + src_cost;

How does this look?

Paolo



More information about the Gcc mailing list