This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Fix profile updating code
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org, rth at redhat dot com, dnovillo at redhat dot com,law at redhat dot com
- Date: Sun, 18 Apr 2004 01:48:30 +0200
- Subject: [tree-ssa] Fix profile updating code
Hi,
this patch plugs several bugs in the tree profilng code on tree-ssa. With this
change the profile comes out consistent for combine.c compilation. The only
non-trivial piece is the updating after jump threading that is basically
cut&paste from rtl version with few comments added.
OK for tree-ssa? Bootstrapped/regtested tree-profilng i686-pc-gnu, tree-ssa in
process.
Honza
2004-04-18 Jan Hubicka <jh@suse.cz>
* tree-cfg.c (tree_split_edge, thread_jumps): Update the profile.
* tree-ssa-dce.c (remove_dead_stmt): Likewise.
* tree-ssa-dom.c (redirect_edges_and_update_ssa_graph): Fix comment.
(thread_across_edge): Update the profile.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.267.2.10
diff -c -3 -p -r1.1.4.267.2.10 tree-cfg.c
*** tree-cfg.c 3 Apr 2004 16:33:35 -0000 1.1.4.267.2.10
--- tree-cfg.c 17 Apr 2004 21:17:43 -0000
*************** tree_split_edge (edge edge_in)
*** 2994,3000 ****
--- 2994,3004 ----
after_bb = edge_in->src;
new_bb = create_empty_bb (after_bb);
+ new_bb->frequency = EDGE_FREQUENCY (edge_in);
+ new_bb->count = edge_in->count;
new_edge = make_edge (new_bb, dest, EDGE_FALLTHRU);
+ new_edge->probability = REG_BR_PROB_BASE;
+ new_edge->count = edge_in->count;
/* Find all the PHI arguments on the original edge, and change them to
the new edge. Do it before redirection, so that the argument does not
*************** thread_jumps (void)
*** 3733,3738 ****
--- 3737,3744 ----
forwardable. */
for (e = bb->succ; e; e = next)
{
+ int freq;
+ gcov_type count;
next = e->succ_next;
/* If the edge is abnormal or its destination is not
*************** thread_jumps (void)
*** 3741,3746 ****
--- 3747,3755 ----
|| !tree_forwarder_block_p (e->dest))
continue;
+ count = e->count;
+ freq = EDGE_FREQUENCY (e);
+
/* Now walk through as many forwarder block as possible to
find the ultimate destination we want to thread our jump
to. */
*************** thread_jumps (void)
*** 3760,3765 ****
--- 3769,3783 ----
break;
bb_ann (dest)->forwardable = 0;
+ dest->frequency -= freq;
+ if (dest->frequency < 0)
+ dest->frequency = 0;
+ dest->count -= count;
+ if (dest->count < 0)
+ dest->count = 0;
+ dest->succ->count -= count;
+ if (dest->succ->count < 0)
+ dest->succ->count = 0;
}
/* Reset the forwardable marks to 1. */
Index: tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
retrieving revision 1.1.2.78.2.3
diff -c -3 -p -r1.1.2.78.2.3 tree-ssa-dce.c
*** tree-ssa-dce.c 30 Mar 2004 23:19:30 -0000 1.1.2.78.2.3
--- tree-ssa-dce.c 17 Apr 2004 21:17:43 -0000
*************** remove_dead_stmt (block_stmt_iterator *i
*** 710,715 ****
--- 710,717 ----
/* Redirect the first edge out of BB to reach POST_DOM_BB. */
redirect_edge_and_branch (bb->succ, post_dom_bb);
PENDING_STMT (bb->succ) = NULL;
+ bb->succ->probability = REG_BR_PROB_BASE;
+ bb->succ->count = bb->count;
/* The edge is no longer associated with a conditional, so it does
not have TRUE/FALSE flags. */
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.135.2.5
diff -c -3 -p -r1.1.2.135.2.5 tree-ssa-dom.c
*** tree-ssa-dom.c 30 Mar 2004 23:19:30 -0000 1.1.2.135.2.5
--- tree-ssa-dom.c 17 Apr 2004 21:17:43 -0000
*************** redirect_edges_and_update_ssa_graph (var
*** 393,399 ****
}
/* Finally, any variables in PHI nodes at our final destination
! must also be taken our of SSA form. */
for (phi = phi_nodes (tgt); phi; phi = TREE_CHAIN (phi))
{
tree result = SSA_NAME_VAR (PHI_RESULT (phi));
--- 393,399 ----
}
/* Finally, any variables in PHI nodes at our final destination
! must also be taken out of SSA form. */
for (phi = phi_nodes (tgt); phi; phi = TREE_CHAIN (phi))
{
tree result = SSA_NAME_VAR (PHI_RESULT (phi));
*************** thread_across_edge (struct dom_walk_data
*** 940,948 ****
--- 940,1000 ----
{
int saved_forwardable = bb_ann (e->src)->forwardable;
edge tmp_edge;
+ int edge_frequency = EDGE_FREQUENCY (e);
+ edge c;
+ int prob;
+
+ e->dest->count -= e->count;
+ if (e->dest->count < 0)
+ e->dest->count = 0;
+
+ /* Compute the probability of TAKEN_EDGE being reached via E.
+ Watch for overflows. */
+ if (e->dest->frequency)
+ prob = edge_frequency * REG_BR_PROB_BASE / e->dest->frequency;
+ else
+ prob = 0;
+ if (prob > taken_edge->probability)
+ prob = taken_edge->probability;
+
+ /* Now rescale the probabilities. */
+ taken_edge->probability -= prob;
+ prob = REG_BR_PROB_BASE - prob;
+ if (prob <= 0)
+ {
+ e->dest->succ->probability = REG_BR_PROB_BASE;
+ for (c = e->dest->succ->succ_next; c; c = c->succ_next)
+ c->probability = 0;
+ }
+ else
+ for (c = e->dest->succ; c; c = c->succ_next)
+ c->probability = ((c->probability * REG_BR_PROB_BASE)
+ / (double) prob);
+ e->dest->frequency -= edge_frequency;
+ if (e->dest->frequency < 0)
+ e->dest->frequency = 0;
bb_ann (e->src)->forwardable = 0;
tmp_edge = tree_block_forwards_to (dest);
+ if (tmp_edge)
+ for (;taken_edge != tmp_edge; taken_edge = taken_edge->dest->succ)
+ {
+ taken_edge->count -= e->count;
+ if (taken_edge->count < 0)
+ taken_edge->count = 0;
+ taken_edge->dest->count -= e->count;
+ if (taken_edge->dest->count < 0)
+ taken_edge->dest->count = 0;
+ taken_edge->dest->frequency -= edge_frequency;
+ if (taken_edge->dest->frequency < 0)
+ taken_edge->dest->frequency = 0;
+ }
+ else
+ {
+ taken_edge->count -= e->count;
+ if (taken_edge->count < 0)
+ taken_edge->count = 0;
+ }
taken_edge = (tmp_edge ? tmp_edge : taken_edge);
bb_ann (e->src)->forwardable = saved_forwardable;
VARRAY_PUSH_EDGE (redirection_edges, e);