Commit d69d0316 by Jan Hubicka Committed by Jan Hubicka

flow.c (last_loop_beg_note): New function.

	* flow.c (last_loop_beg_note): New function.
	(redirect_edge_and_branch): Use it.
	(split_edge): Likewise.

	* alias.c (loop_p): Avoid uninitialized memory access.

	* flow.c (try_forward_edges): Avoid accessing freed memory.

	* flow.c (backward_edge_of_syntactic_loop_p): Avoid uninitialized
	variable access.

From-SVN: r44429
parent f636e2a5
Fri Jul 27 17:53:00 CEST 2001 Jan Hubicka <jh@suse.cz>
* flow.c (last_loop_beg_note): New function.
(redirect_edge_and_branch): Use it.
(split_edge): Likewise.
* alias.c (loop_p): Avoid uninitialized memory access.
* flow.c (try_forward_edges): Avoid accessing freed memory.
* flow.c (backward_edge_of_syntactic_loop_p): Avoid uninitialized
variable access.
2001-07-27 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> 2001-07-27 Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* doc/install.texi (Configuration): Properly link the host * doc/install.texi (Configuration): Properly link the host
......
...@@ -2118,7 +2118,7 @@ loop_p () ...@@ -2118,7 +2118,7 @@ loop_p ()
} }
else else
{ {
if (dest != EXIT_BLOCK_PTR if (dest != EXIT_BLOCK_PTR && src != ENTRY_BLOCK_PTR
&& pre[src->index] >= pre[dest->index] && pre[src->index] >= pre[dest->index]
&& post[dest->index] == 0) && post[dest->index] == 0)
break; break;
......
...@@ -1748,6 +1748,30 @@ try_redirect_by_replacing_jump (e, target) ...@@ -1748,6 +1748,30 @@ try_redirect_by_replacing_jump (e, target)
return true; return true;
} }
/* Return last loop_beg note appearing after INSN, before start of next
basic block. Return INSN if there are no such notes.
When emmiting jump to redirect an fallthru edge, it should always
appear after the LOOP_BEG notes, as loop optimizer expect loop to
eighter start by fallthru edge or jump following the LOOP_BEG note
jumping to the loop exit test.
*/
rtx
last_loop_beg_note (insn)
rtx insn;
{
rtx last = insn;
insn = NEXT_INSN (insn);
while (GET_CODE (insn) == NOTE
&& NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
{
if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
last = insn;
insn = NEXT_INSN (insn);
}
return last;
}
/* Attempt to change code to redirect edge E to TARGET. /* Attempt to change code to redirect edge E to TARGET.
Don't do that on expense of adding new instructions or reordering Don't do that on expense of adding new instructions or reordering
basic blocks. basic blocks.
...@@ -1877,7 +1901,8 @@ redirect_edge_and_branch_force (e, target) ...@@ -1877,7 +1901,8 @@ redirect_edge_and_branch_force (e, target)
/* Case of the fallthru block. */ /* Case of the fallthru block. */
if (!e->src->succ->succ_next) if (!e->src->succ->succ_next)
{ {
e->src->end = emit_jump_insn_after (gen_jump (label), e->src->end); e->src->end = emit_jump_insn_after (gen_jump (label),
last_loop_beg_note (e->src->end));
JUMP_LABEL (e->src->end) = label; JUMP_LABEL (e->src->end) = label;
LABEL_NUSES (label)++; LABEL_NUSES (label)++;
if (basic_block_for_insn) if (basic_block_for_insn)
...@@ -1906,7 +1931,7 @@ redirect_edge_and_branch_force (e, target) ...@@ -1906,7 +1931,7 @@ redirect_edge_and_branch_force (e, target)
memset (new_bb, 0, sizeof (*new_bb)); memset (new_bb, 0, sizeof (*new_bb));
new_bb->end = new_bb->head = e->src->end; new_bb->end = new_bb->head = last_loop_beg_note (e->src->end);
new_bb->succ = NULL; new_bb->succ = NULL;
new_bb->pred = new_edge; new_bb->pred = new_edge;
new_bb->count = e->count; new_bb->count = e->count;
...@@ -1976,7 +2001,7 @@ back_edge_of_syntactic_loop_p (bb1, bb2) ...@@ -1976,7 +2001,7 @@ back_edge_of_syntactic_loop_p (bb1, bb2)
basic_block bb1, bb2; basic_block bb1, bb2;
{ {
rtx insn; rtx insn;
int count; int count = 0;
if (bb1->index > bb2->index) if (bb1->index > bb2->index)
return false; return false;
if (bb1->index == bb2->index) if (bb1->index == bb2->index)
...@@ -2088,7 +2113,7 @@ split_edge (edge_in) ...@@ -2088,7 +2113,7 @@ split_edge (edge_in)
/* Now add the jump insn ... */ /* Now add the jump insn ... */
pos = emit_jump_insn_after (gen_jump (old_succ->head), pos = emit_jump_insn_after (gen_jump (old_succ->head),
jump_block->end); last_loop_beg_note (jump_block->end));
jump_block->end = pos; jump_block->end = pos;
if (basic_block_for_insn) if (basic_block_for_insn)
set_block_for_new_insns (pos, jump_block); set_block_for_new_insns (pos, jump_block);
...@@ -3159,29 +3184,38 @@ try_forward_edges (b) ...@@ -3159,29 +3184,38 @@ try_forward_edges (b)
} }
else if (target == first) else if (target == first)
; /* We didn't do anything. */ ; /* We didn't do anything. */
else if (redirect_edge_and_branch (e, target)) else
{ {
/* We successfully forwarded the edge. Now update profile /* Save the values now, as the edge may get removed. */
data: for each edge we traversed in the chain, remove gcov_type edge_count = e->count;
the original edge's execution count. */ int edge_probability = e->probability;
do
if (redirect_edge_and_branch (e, target))
{ {
first->count -= e->count; /* We successfully forwarded the edge. Now update profile
first->succ->count -= e->count; data: for each edge we traversed in the chain, remove
first->frequency -= ((e->probability * b->frequency the original edge's execution count. */
+ REG_BR_PROB_BASE / 2) int edge_frequency = ((edge_probability * b->frequency
/ REG_BR_PROB_BASE); + REG_BR_PROB_BASE / 2)
first = first->succ->dest; / REG_BR_PROB_BASE);
}
while (first != target); do
{
first->count -= edge_count;
first->succ->count -= edge_count;
first->frequency -= edge_frequency;
first = first->succ->dest;
}
while (first != target);
changed = true; changed = true;
} }
else else
{ {
if (rtl_dump_file) if (rtl_dump_file)
fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n", fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n",
b->index, e->dest->index, target->index); b->index, e->dest->index, target->index);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment