Signed divide by 2 pessimization

Marek Michalkiewicz
Sat Sep 16 12:53:00 GMT 2000

Geoff Keating <> wrote:
> Just make rtx_cost deal with branch instructions.  It's not very hard;
> a branch looks like (set (pc) (if_then_else (eq ...) (label_ref ...) (pc)))
> so detect the if_then_else and the (pc) and return the appropriate
> value.  It need not work for every case, so long as this is documented.

Now that the COSTS_N_INSNS define has been moved to rtl.h, I think using
COSTS_N_INSNS (BRANCH_COST) directly (at least for now) would be much
simpler, so I would prefer that for now.  (I can try to enhance rtx_cost
and use that later, but I think that would be a separate logical change.)

Testing my change a bit more, I noticed a problem with using shift_cost[]
(possibly not just in my change, but also in other places - I'm not sure) -
this array has MAX_BITS_PER_WORD elements, which defaults to BITS_PER_WORD,
which is defined as 8 in the AVR port.  But the shift counts can be larger
(size can be 32), resulting in bogus cost values (array index out of range).

Now, what would be the best way to get around this?  (AVR has 32 general
8-bit registers, but QI/HI/SI/DI modes are as usual, 8/16/32/64 bits.)
Should the AVR port define MAX_BITS_PER_WORD as 32 (even if BITS_PER_WORD
is always 8), or will that cause problems in other places?  Denis?

> The problem is that the hack itself has a cost.  Someone will
> eventually have to do the work properly anyway; and with the hack,
> that someone will then have to try to work out what this hack is
> doing, why it was needed, and what each port does with it, and then
> when the hack goes away each port which used it will have to be
> checked to see that it got the costs right.

I understand that problem in general, but have you seen the hack?
It is very small, I can document it better in the comments, and
I will be happy to explain it to that someone if necessary.

> I'm not saying that such hacks don't have a place; it's just that
> their place is in your local tree, not in the master repository.

The problem is, there may be a few users of this port who don't have
my local tree.  I can distribute my changes as unofficial patches,
but that is just moving the cost to the users.

Don't get me wrong.  I too would prefer to do everything right from
the start, but if that is hard for some reason, I think a temporary
hack which makes better code is better (for the users) than nothing.


More information about the Gcc mailing list