This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: redirect_edge_and_branch questions


> I have a couple of questions about redirecting edges in SSA.
> 
> AS a part of SSA->normal, we sometimes insert stmts on incoming edges to
> blocks with PHI nodes. I can now detect when the same stmts are being
> issued on multiple edges, and issue the stmts once.  These stmts are
> issued either into a new block, or an existing one if there are no stmts
> in it (other than a label). The remaining edges are then redirected to
> that block.
> 
> So there appears to be two issues. 
> 
> First, This proceeds to invalidate the dominators. Right now, I simply
> delete the existing dominators since SA->normal doesn't care about them
> anyway.   Does anything *after* SSA->normal use dominators, requiring
> them to be recalculated?
> And aside from that, why doesn't redirect_edge_and_branch() do whatever
> dominator updates are required. It has exactly the same information I
> have if I wanted to update them.

No, it doesn't.
It is dificult to effectivly update dominator tree when you know just
that you are redirecting edge from block A to B, while it is trivial
when you know, for instance, that you are splitting block into two.
So updating dominators relies on higher level knowledge of what is going
on.
> 
> Second, after performing these edge redirections, I get the following
> kinds of warnings:
> 
> <L10>:;
>   D.1121 = 0;
>   goto <bb 4> (<L6>);
> Invalid sum of incoming frequencies 8519, should be 3008
> <L4>:;
>   D.1121 = 1;
> Invalid sum of incoming frequencies 4489, should be 10000
> <L6>:;
>   return D.1121;
> 
> So my next question is why doesn't redirect_edge_and_branch() also
> update the block frequencies?   Again, it has the same information I
> have...

It does not again.  For instance if you are moving edge to skip
forwarder block, it is trivial to walk the path and update, but for
instance when you are doing jump threading, it is already nontrivial
issue, so again you have to know why you are redirecting the edge and
how.

In your case the frequencies updating is quite trivial - you need to sum
EDGE_FREQUENCY of all edges you redirect into your block and set basic
block frequency accordingly.  Similarly you need to sum the counts and
set basic block/outgoing edge count.  Finally set outgoing edge
probability to REG_BR_PROB_BASE (that might be already done depending
how you create the block).

Perhaps it would make sense to have function that takes list of
incomming edges to given basic block and create empty basic block before
redirecting the selected edges into it.  This operatinon should be
usefull at least for creating loop preheaders.

Honza
> 
> Andrew 
> 
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]