This is the mail archive of the gcc@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]

inadequate multiply-by-const expansion for pentium4


Hi all
I played a bit to see how gcc expands multiplication by various constants in
leas/adds/subs/shifts and found that it does not do the job in the best possible
way it could. I tracked for the the reason and found 3 different problems:

 1) the cost of an add insn for p4 (in config/i386/i386.c) is 1 while
    it should be 0.5 (or probably 1 with all other costs doubled)

 2) that x86_decompose_lea flag is causing invalid cost evaluation for
    the lea insn (in gcc/expmed.c, init_expmed())- the evaluated cost is much
    higher than the real one so that for example the compiler uses shl instead
    of lea for multiplying by 4 and 8, although the cost of an shift is 4 times
    that of an lea for p4

 3) look at the followind code in gcc/expmed.c, expand_mult():
      mult_cost = rtx_cost (gen_rtx_MULT (mode, op0, op1), SET);
      mult_cost = MIN (12 * add_cost, mult_cost);
    this is how the upper bounding cost is calculated before the recursive
    search for an expansion is invoked. The second line looks quite weird and
    arbitrary to me. Why the cost is capped in such an artificial way by
    the costs of 12 adds (in p4 the cost of an mul is 28-30 times that of an add).
    As a result, the compiler ends up using the expensive imul (instead of some
    add/shift/lea expansion) much frequently than the optimal. I tried for
    constants up to 1000. Generally if the expansion would be longer than 5-6
    instructions, gcc uses imul. I also checked what the Intel's compiler do
    and found that it _never_ uses imul (i tested up to 1000) even though for
    some constants it ends up with quite long sequences of adds/subs/leas/shifts.

lucho


	
		
__________________________________
Do you Yahoo!?
Yahoo! Photos: High-quality 4x6 digital prints for 25¢
http://photos.yahoo.com/ph/print_splash


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