Graham Stott <graham.st...@btinternet.com> writes:
> When -Os is used and the multiplier is of the for 2^N +- 1 we generate
> a MUL instruction rather that a shift-left N and add-sub 1.
> 
> The problem is that rtx cost for the MUL is too cheap causing the
> shift-left and add-sub sequence to be more expensive.
> 
> This patch makes the MUL slightly more expension so the alternate
> sequence and better sequence used. The shift + add/sub is faster and
> can probaly be scheduled better.
> 
> This change is code size neutral because the MUL requires a load-immediate.

Hmm, but this code is giving the cost of the multiplication itself.
The cost of the immediate is added separately due to the "return false".
I'd have expected the cumulative cost of constant multiplications to be 2
for ISA_HAS_MULS and 3 for !ISA_HAS_MUL3, which sounds correct.

So is the problem that we have two sequences with identical cost and
GCC isn't sure which to pick?  If so:

  *total = COSTS_N_INSNS (ISA_HAS_MUL3 ? 1 : 2) + 1;

(i.e. a sub-insn bias) would be OK.  There should be a testcase though.

Thanks,
Richard

Reply via email to