New optimization for reload_combine

Bernd Schmidt bernds@codesourcery.com
Fri Jul 16 19:55:00 GMT 2010


On 07/16/2010 09:45 PM, Paolo Bonzini wrote:
> On 07/16/2010 12:34 PM, Bernd Schmidt wrote:

>> This can make the generated code quite a lot nicer:
>>
>> -       adds    r3, r2, #2
>>          strb    r5, [r2, #0]
>> -       strb    r5, [r3, #0]
>> -       adds    r3, r2, #3
>> +       strb    r5, [r2, #2]
>>          strb    r5, [r2, #1]
>> -       strb    r5, [r3, #0]
>> -       adds    r3, r2, #4
>> +       strb    r5, [r2, #3]
>>          lsrs    r1, r1, #11
>> -       strb    r5, [r3, #0]
>> -       adds    r3, r2, #5
>> +       strb    r5, [r2, #4]
>>          add     r1, r1, r1, lsl #1
>> -       strb    r5, [r3, #0]
>> +       strb    r5, [r2, #5]
> 
> Nice. :)  I suppose fwprop doesn't do it because the memory accesses are
> not present before reload?

I haven't checked, but I guess in many cases (i.e. anything
stack-relative) that's the case.  Also, some of the adds are produced by
reload_cse_move2add.

> Can you make the change dependent on
> 
>   bool speed = optimize_bb_for_speed_p (BLOCK_FOR_INSN (insn));
> 
>   /* Prefer the new address if it is less expensive.  */
>   gain = (address_cost (old_rtx, mode, as, speed)
>           - address_cost (new_rtx, mode, as, speed));
> 
>   /* If the addresses have equivalent cost, prefer the new address
>      if it has the highest `rtx_cost'.  That has the potential of
>      eliminating the most insns without additional costs, and it
>      is the same that cse.c used to do.  */
>   if (gain == 0)
>     gain = rtx_cost (new_rtx, SET, speed) - rtx_cost (old_rtx, SET, speed);
> 
>   return (gain > 0);
> 
> as in fwprop (in turn taken from CSE)?

I guess I can use address_cost instead of rtx_cost.  I'll make the
change if it still gives me good results.  The extra rtx_cost check you
quoted doesn't seem worthwhile here, as the goal mentioned in the
comment (i.e, eliminating the add) is achievable only if we do the
replacement every time.

As a followup, it would be nice to compute all the costs before
replacing anything, and taking into account whether the add is dead.


Bernd



More information about the Gcc-patches mailing list