A few little loop.c cleanup patches

Richard Henderson rth@cygnus.com
Fri Aug 25 13:15:00 GMT 2000


On Sun, Aug 27, 2000 at 01:29:28AM +1200, Michael Hayes wrote:
> 5.4 Find induction variables.
> 
> 5.5 Perform loop inversion optimizations.
> 
> 5.6 Perform strength reduction of induction variables.
> 
> 5.7 Perform induction variable elimination.
> 
> 5.8 Perform local lifetime analysis if register references moved.
> 
> 5.9 Perform loop unrolling.

Wouldn't you want to do unrolling before strength reduction?  Given
something like

        for (i = 0; i < 100; ++i)
          x[i] += 2;

and a machine with sensible displacements, you'd want the x+0, x+4, 
x+8, x+12 to use one reduced register.  I'm not sure how this is
handled now (or if it is), but surely it would be easier to just
do unrolling earlier.

> The aspects I have not got a good handle on yet are:
> 
>  (1) how to perform lifetime analysis over portions of the CFG; for
>      example, just the nodes of a natural loop?

(a) update_life_info will work with an sbitmap of blocks,
(b) propagate_block will do one basic block,
(c) init_propagate_block_info + propagate_one_insn will do single insns.

Except for some wiggle words wrt UPDATE_LIFE_GLOBAL and nodes internal
to the subgraph, all require that bb->global_live_at_end is correct.
Which pretty much requires that you've run a global life analysis in
the moderately recent past and not confused things too much in the 
meantime.

>  (2) how to redirect edges in the CFG to ensure that there is a pre-header.

Depending on how complicated the transformation,

(a) use insert_insn_on_edge with NOTE_INSN_DELETED,
(b) use create_basic_block to create the block, fiddle around
    with the indices yourself, and use make_edge and redirect_edge
    to fix up the CFG.


r~


More information about the Gcc-patches mailing list