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] Tweak cost of lea on Pentium4


> 
> The following patch fixes a problem with the parameterization of the x86's
> lea instruction on the Pentium4.  The issue is that the i386 backend's
> target macro TARGET_DECOMPOSE_LEA, results in GCC over-estimating the cost
> of "lea" on the Pentium4.  This macro was introduced by Jan back in 2001,
> http://gcc.gnu.org/ml/gcc/2001-11/msg00308.html, in an attempt to generate
> better code for Pentium class machines.  As mentioned in that post, the
> "lea" instruction is slower on Pentium4 than earlier cores where it had
> typically cost only a single cycle.
> 
> The solution proposed by Jan was to introduce TARGET_DECOMPOSE_LEA, so
> that the x86_rtx_cost function would ignore the existance of the "lea"
> instruction patterns on affected cores.  Unfortunately, this approach is
> far too Draconian, resulting in "(plus (mult (reg) (const_int 4)) (reg))"
> costing the equivalent of an addition *and* a full multiplication.  With
> a multiplication on pentium4 taking 15 cycles [or COST_N_INSNS (15) in
> i386.c], the cost of an using "lea" is currently a huge 16 cycles!
> Of course, 16 cycles is far too high.  At worst, Intel's microcode would
> decompose an "lea" into a shift and an add, costing at most 5 cycles.

The idea was that P4 and some of earlier cores executes lea in same time
as if it were equivalent sequence of primitive operations (shifts and
adds). This is still what P4 does.  I think all we need with the old
scheme is to teach rtx_cost that multiplication by power of 2 is in fact
shifting and thus it is significantly cheaper.  Then the pattern above
would result in 3 cycles as you suggest, while more complex leas will be
more expensive....

Honza


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