This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix shift-and-add costs in rs6000_rtx_costs


On Sun, 11 Jul 2004, David Edelsohn wrote:
> >>>>> Roger Sayle writes:
> > The following patch tweaks the rs6000's TARGET_RTX_COST function to
> > indicate that it doesn't have shift-and-add or shift-and-sub insns.
> > The middle-end's expmed_init calls rtx_cost on the RTL pattern
> > (plus (mult (reg) (const_int)) (reg)), to determine whether the backend
> > has shift-and-add or shift-and-sub instructions that can be used to
> > efficiently implement synthetic multiply.
>
> 	Is this change going to disable shift-and-add for all multiplies?
> We do want to use shift-and-add where the cost for the two instructions
> is less than the cost of a multiply.

No, we'll still generate individual shifts and adds, we're just trying
to disable the middle-end thinking it has an extremely cheap single-cycle
shift-and-add instruction.  The relevant code in expmed.c is:

>>         cost = add_cost[mode] + shift_cost[mode][m];
>>         if (shiftadd_cost[mode][m] < cost)
>>           cost = shiftadd_cost[mode][m];

On most PPC targets add_cost and shift_cost are each COSTS_N_INSNS(1).
The problem is that we currently also return COSTS_N_INSNS(1) for a
mythical "lea"-like instruction, so synth_mult underestimates the cost
of a shift followed by an addition.

For this patch, it isn't important that the multiplication subexpressions
are powers of two and can therefore be implemented by a single cycle shift.
All that's required is that the value must be at least COSTS_N_INSNS(2).

Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]