[PATCH] Fix canonicalization of addresses

Eric Botcazou ebotcazou@adacore.com
Wed Jan 7 18:40:00 GMT 2009

> Yes.  But then CSE should work on either canonical form - if we change
> the canonical form we just treat one missed-optimization for another.

What missed optimization?  Your 2005 change wasn't related to offsets but to 
user expressions of a certain form.  Flipping back the canonicalization for 
offsets won't change the behavior for these expressions.

CSE work equally well on both form per se, simply the result is not well 
suited to the (REG+disp) addressing mode most architecture have when the
base or indexes vary because REG will vary, which is not free; on the 
contrary, making the displacement vary is free.  That's what the comment
in extract_muldiv was hinting at.

> IVOPTs comes into play because IVOPTs has non-local knowledge to
> decide which canonical form is better - or rather IVOPTs will try to
> generate a target friendly TARGET_MEM_REF operation minimizing
> the number of induction variables and the address cost.  I just do not
> see that we have proper information elsewhere on trees - apart from
> the possibility to just decide globally that one form is better than the
> other.

Yes, for offsets one form is clearly better at low level.

> So this problem exists with both -Os and -O2 then?

I've written more than a couple of times that the testcase that prompted me to 
write the patch was on PowerPC at -O2. :-)

Eric Botcazou

More information about the Gcc-patches mailing list