https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108519

--- Comment #1 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
We diverge in sched1 due to extra calls to advance_one_cycle when scheduling a
BB that is empty apart from one debug insn. The following patch adds a hexdump
of automaton state to make the problem evident:

diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc
index 420c45dff..c09398897 100644
--- a/gcc/sched-rgn.cc
+++ b/gcc/sched-rgn.cc
@@ -3098,8 +3098,14 @@ save_state_for_fallthru_edge (basic_block last_bb,
state_t state)
     memcpy (bb_state[f->dest->index], state,
            dfa_state_size);
     if (sched_verbose >= 5)
-      fprintf (sched_dump, "saving state for edge %d->%d\n",
-              f->src->index, f->dest->index);
+      {
+       fprintf (sched_dump, "saving state for edge %d->%d\n",
+                f->src->index, f->dest->index);
+       for (size_t i = 0; i < dfa_state_size; i++)
+         fprintf (sched_dump, "%02x%c", i[(unsigned char *)state],
+                  (i+1) % 16 ? ' ' : '\n');
+       fprintf(sched_dump, "\n---\n");
+      }
   }
 }

With the above patch it's obvious we advance the automaton state a few extra
times when scheduling BB 3, and then inherit the modified state to BB 4.

I think we don't need to schedule blocks that only contain debug insns. IBM
folks, care to test the following?

diff --git a/gcc/haifa-sched.cc b/gcc/haifa-sched.cc
index 4efaa9445..f00a92e26 100644
--- a/gcc/haifa-sched.cc
+++ b/gcc/haifa-sched.cc
@@ -5040,7 +5040,7 @@ no_real_insns_p (const rtx_insn *head, const rtx_insn
*tail)
 {
   while (head != NEXT_INSN (tail))
     {
-      if (!NOTE_P (head) && !LABEL_P (head))
+      if (!NOTE_P (head) && !LABEL_P (head) && !DEBUG_INSN_P (head))
        return 0;
       head = NEXT_INSN (head);
     }
diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc
index 420c45dff..c09398897 100644
--- a/gcc/sched-rgn.cc
+++ b/gcc/sched-rgn.cc
@@ -2753,7 +2753,7 @@ free_block_dependencies (int bb)

   get_ebb_head_tail (EBB_FIRST_BB (bb), EBB_LAST_BB (bb), &head, &tail);

-  if (no_real_insns_p (head, tail))
+  if (0 && no_real_insns_p (head, tail))
     return;

   sched_free_deps (head, tail, true);

Reply via email to