[PATCH] Fix canonicalization of addresses

Richard Guenther richard.guenther@gmail.com
Tue Jan 6 20:09:00 GMT 2009


On Tue, Jan 6, 2009 at 4:13 PM, Richard Earnshaw <rearnsha@arm.com> wrote:
> On Tue, 2009-01-06 at 15:17 +0100, Eric Botcazou wrote:
>> > In the above case transforming -A * -CST to A * CST (which would handle
>> > the (1 - ind) * -2 case also if witten that way by a user, not only if
>> > generated by fold_plusminus_mult).  Thus, it subsumes the plusminus_mult
>> > patch in favor of a IMHO better one.
>>
>> I disagree.  The factorization by a negative power of 2 in plusminus_mult
>> doesn't serve any useful purpose and can be harmful, as shown here; instead
>> of relying on a later transformation to repair the damages, let's not create
>> them in the first place, this will save both time and memory.
>
> Seconded.  Furthermore, subtraction of a variable from a constant is
> less widely supported in CPUs than addition of small negative numbers --
> ie subtracting a constant (The Thumb instruction set has sub reg, const,
> but not sub const, reg).

To repeat: it's a canonicalization.  And it helps for canonicalizing a
* (-2) - 8 to (a + 4)*(-2)
and allowing CSE with another a + 4.  I don't think that in this case
we want to have
(-4 - a)*2.

And properly canonicalizing (1 - ind) * -2 to (ind - 1) * 2 is correct
anyway.  And as this
would exactly DTRT on the cases you complain about this is the correct
thing to do!
Instead of complicating an unrelated canonicalization routine.

Richard.



More information about the Gcc-patches mailing list