More than you ever wanted to know about Fortran array indexing;-)
Toon Moene
toon@moene.indiv.nluug.nl
Tue Oct 7 23:14:00 GMT 1997
> Only, I would like to see loop take y[i-1], y[i], y[i+1],
> make one induction variable, and use -4(R), 0(R), 4(R)
> in the loop. Hmm...
I wrote that that would be a nice follow on project, but it turns
out that gcc already knows how to do that; unfortunately, the
function that decides about this optimisation almost never applies
it.
I am talking about `combine_givs_p' in loop.c. Basically it says:
If a giv G2 can be expressed as a function of giv G1 and that
function is a valid address expression, and the resulting addressing
mode is cheaper than the original, then do not reduce G2.
I think the cost/benefit reasoning here is flawed. First of all,
if G2 is reduced, you need to include the increment it needs at the
end of the loop in its cost. More important, however, is that you
need an extra register ! Therefore, it is almost always cheaper to
combine those givs than to keep them separate.
Another flaw of combine_givs_p is that it uses ADDRESS_COST, a
macro that's not defined for every architecture gcc supports, but it
doesn't use a backup like RTX_COST if it isn't. This already lead
to one hard to find bug.
I'll try out tonight what happens if I simply bypass its cost
calculation ...
Cheers,
Toon.
More information about the Gcc
mailing list