This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[rtlopt] bb-reorder fix
- From: Josef Zlomek <zlomj9am at artax dot karlin dot mff dot cuni dot cz>
- To: gcc-patches at gcc dot gnu dot org,Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>,Jan Hubicka <jh at suse dot cz>
- Date: Sun, 15 Dec 2002 21:37:00 +0100
- Subject: [rtlopt] bb-reorder fix
Hi,
I have fixed the problem in bb_to_key () and have fixed some problems in
connect_traces () but I'm not sure I have fixed the problem with
accessing index -1 of array.
I'm bootstrapping it right now.
Zdenek, please could you check it by valgrind again?
Josef
Sun Dec 15 21:35:47 CET 2002 Josef Zlomek <zlomj9am@artax.karlin.mff.cuni.cz>
* bb-reorder.c (bb_to_key): Fix accessing index -1 of array.
(connect_traces): Fix several bugs.
Index: bb-reorder.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/bb-reorder.c,v
retrieving revision 1.50.2.16
diff -c -3 -p -r1.50.2.16 bb-reorder.c
*** bb-reorder.c 15 Dec 2002 17:38:10 -0000 1.50.2.16
--- bb-reorder.c 15 Dec 2002 20:02:30 -0000
*************** bb_to_key (bb)
*** 732,739 ****
trace. */
for (e = bb->pred; e; e = e->pred_next)
{
! int index = e->src->index;
! if (end_of_trace[index] >= 0)
{
priority++;
break;
--- 732,738 ----
trace. */
for (e = bb->pred; e; e = e->pred_next)
{
! if (e->src != ENTRY_BLOCK_PTR && end_of_trace[e->src->index] >= 0)
{
priority++;
break;
*************** connect_traces (n_traces, traces)
*** 816,991 ****
{
int t = i;
int t2;
! if (!connected[t])
! {
! edge e, best;
! int best_len;
! connected[t] = true;
! /* Find the predecessor traces. */
! for (t2 = t; t2 > 0;)
{
! best = NULL;
! best_len = 0;
! for (e = traces[t2].first->pred; e; e = e->pred_next)
! {
! int si = e->src->index;
! if (e->src != ENTRY_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && !(e->flags & EDGE_COMPLEX)
! && end_of_trace[si] >= 0
! && !connected[end_of_trace[si]]
! && (!best
! || e->probability > best->probability
! || (e->probability == best->probability
! && traces[end_of_trace[si]].length > best_len)))
! {
! best = e;
! best_len = traces[end_of_trace[si]].length;
! }
}
! if (best)
{
! RBI (best->src)->next = best->dest;
! t2 = end_of_trace[best->src->index];
! connected[t2] = true;
! if (rtl_dump_file)
! {
! fprintf (rtl_dump_file, "Connection: %d %d\n",
! best->src->index, best->dest->index);
! }
}
- else
- break;
}
! if (last_trace >= 0)
! RBI (traces[last_trace].last)->next = traces[t2].first;
! last_trace = t;
! /* Find the successor traces. */
! for (;;)
{
! /* Find the continuation of the chain. */
! best = NULL;
! best_len = 0;
! for (e = traces[t].last->succ; e; e = e->succ_next)
! {
! int di = e->dest->index;
! if (e->dest != EXIT_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && !(e->flags & EDGE_COMPLEX)
! && start_of_trace[di] >= 0
! && !connected[start_of_trace[di]]
! && (!best
! || e->probability > best->probability
! || (e->probability == best->probability
! && traces[end_of_trace[di]].length > best_len)))
! {
! best = e;
! best_len = traces[end_of_trace[di]].length;
! }
}
! if (best)
{
! if (rtl_dump_file)
! {
! fprintf (rtl_dump_file, "Connection: %d %d\n",
! best->src->index, best->dest->index);
! }
}
! else
! {
! /* Try to connect the traces by duplication of 1 block. */
! edge e2;
! basic_block next_bb;
! for (e = traces[t].last->succ; e; e = e->succ_next)
! if (e->dest != EXIT_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && (EDGE_FREQUENCY (e) >= freq_threshold)
! && (e->count >= count_threshold)
! && (!best
! || e->probability > best->probability))
{
! edge best2 = NULL;
! int best2_len = 0;
! for (e2 = e->dest->succ; e2; e2 = e2->succ_next)
{
! int di = e2->dest->index;
!
! if (e2->dest == EXIT_BLOCK_PTR
! || ((e2->flags & EDGE_CAN_FALLTHRU)
! && start_of_trace[di] >= 0
! && !connected[start_of_trace[di]]
! && (EDGE_FREQUENCY (e2) >= freq_threshold)
! && (e2->count >= count_threshold)
! && (!best2
! || e2->probability > best2->probability
! || (e2->probability
! == best2->probability
! && traces[end_of_trace[di]].length
! > best2_len))))
! {
! best = e;
! best2 = e2;
! if (e2->dest != EXIT_BLOCK_PTR)
! best2_len = traces[start_of_trace[di]].length;
! else
! best2_len = INT_MAX;
! next_bb = e2->dest;
! }
}
}
! if (best)
{
! if (copy_bb_p (best->dest))
! {
! basic_block new_bb;
!
! if (rtl_dump_file)
! {
! fprintf (rtl_dump_file, "Connection: %d %d ",
! traces[t].last->index,
! best->dest->index);
! if (next_bb == EXIT_BLOCK_PTR)
! fprintf (rtl_dump_file, "exit\n");
! else
! fprintf (rtl_dump_file, "%d\n", next_bb->index);
! }
!
! new_bb = copy_bb (best->dest, best,
! traces[t].last, t);
! traces[t].last = new_bb;
! if (next_bb != EXIT_BLOCK_PTR)
! {
! for (best = new_bb->succ; best;
! best = best->succ_next)
! if (best->dest == next_bb)
! break;
! }
! else
! best = NULL;
! }
else
! best = NULL;
}
- }
! if (best)
! {
! t = start_of_trace[best->dest->index];
! RBI (traces[last_trace].last)->next = traces[t].first;
! connected[t] = true;
! last_trace = t;
}
else
! break;
}
}
}
--- 815,980 ----
{
int t = i;
int t2;
+ edge e, best;
+ int best_len;
! if (connected[t])
! continue;
! connected[t] = true;
! /* Find the predecessor traces. */
! for (t2 = t; t2 > 0;)
! {
! best = NULL;
! best_len = 0;
! for (e = traces[t2].first->pred; e; e = e->pred_next)
{
! int si = e->src->index;
! if (e->src != ENTRY_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && !(e->flags & EDGE_COMPLEX)
! && end_of_trace[si] >= 0
! && !connected[end_of_trace[si]]
! && (!best
! || e->probability > best->probability
! || (e->probability == best->probability
! && traces[end_of_trace[si]].length > best_len)))
! {
! best = e;
! best_len = traces[end_of_trace[si]].length;
}
! }
! if (best)
! {
! RBI (best->src)->next = best->dest;
! t2 = end_of_trace[best->src->index];
! connected[t2] = true;
! if (rtl_dump_file)
{
! fprintf (rtl_dump_file, "Connection: %d %d\n",
! best->src->index, best->dest->index);
}
}
+ else
+ break;
+ }
! if (last_trace >= 0)
! RBI (traces[last_trace].last)->next = traces[t2].first;
! last_trace = t;
! /* Find the successor traces. */
! while (1)
! {
! /* Find the continuation of the chain. */
! best = NULL;
! best_len = 0;
! for (e = traces[t].last->succ; e; e = e->succ_next)
{
! int di = e->dest->index;
! if (e->dest != EXIT_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && !(e->flags & EDGE_COMPLEX)
! && start_of_trace[di] >= 0
! && !connected[start_of_trace[di]]
! && (!best
! || e->probability > best->probability
! || (e->probability == best->probability
! && traces[start_of_trace[di]].length > best_len)))
! {
! best = e;
! best_len = traces[start_of_trace[di]].length;
}
+ }
! if (best)
! {
! if (rtl_dump_file)
{
! fprintf (rtl_dump_file, "Connection: %d %d\n",
! best->src->index, best->dest->index);
}
! t = start_of_trace[best->dest->index];
! RBI (traces[last_trace].last)->next = traces[t].first;
! connected[t] = true;
! last_trace = t;
! }
! else
! {
! /* Try to connect the traces by duplication of 1 block. */
! edge e2;
! basic_block next_bb;
!
! for (e = traces[t].last->succ; e; e = e->succ_next)
! if (e->dest != EXIT_BLOCK_PTR
! && (e->flags & EDGE_CAN_FALLTHRU)
! && !(e->flags & EDGE_COMPLEX)
! && (EDGE_FREQUENCY (e) >= freq_threshold)
! && (e->count >= count_threshold)
! && (!best
! || e->probability > best->probability))
! {
! edge best2 = NULL;
! int best2_len = 0;
!
! for (e2 = e->dest->succ; e2; e2 = e2->succ_next)
{
! int di = e2->dest->index;
! if (e2->dest == EXIT_BLOCK_PTR
! || ((e2->flags & EDGE_CAN_FALLTHRU)
! && !(e2->flags & EDGE_COMPLEX)
! && start_of_trace[di] >= 0
! && !connected[start_of_trace[di]]
! && (EDGE_FREQUENCY (e2) >= freq_threshold)
! && (e2->count >= count_threshold)
! && (!best2
! || e2->probability > best2->probability
! || (e2->probability == best2->probability
! && traces[start_of_trace[di]].length
! > best2_len))))
{
! best = e;
! best2 = e2;
! if (e2->dest != EXIT_BLOCK_PTR)
! best2_len = traces[start_of_trace[di]].length;
! else
! best2_len = INT_MAX;
! next_bb = e2->dest;
}
}
! }
! if (best && copy_bb_p (best->dest))
! {
! basic_block new_bb;
!
! if (rtl_dump_file)
{
! fprintf (rtl_dump_file, "Connection: %d %d ",
! traces[t].last->index, best->dest->index);
! if (next_bb == EXIT_BLOCK_PTR)
! fprintf (rtl_dump_file, "exit\n");
else
! fprintf (rtl_dump_file, "%d\n", next_bb->index);
}
! new_bb = copy_bb (best->dest, best, traces[t].last, t);
! traces[t].last = new_bb;
! if (next_bb != EXIT_BLOCK_PTR)
! {
! t = start_of_trace[next_bb->index];
! RBI (traces[last_trace].last)->next = traces[t].first;
! connected[t] = true;
! last_trace = t;
! }
! else
! break; /* Stop finding the successor traces. */
}
else
! break; /* Stop finding the successor traces. */
}
}
}