From ef259ebeb39501bfddcc7c203a9a7a0daefa8ffd Mon Sep 17 00:00:00 2001
From: Kewen Lin <linkw@linux.ibm.com>
Date: Wed, 20 Dec 2023 21:21:54 -0600
Subject: [PATCH] sched: Remove debug counter sched_block

Currently the debug counter sched_block doesn't work well
since we create dependencies for some insns and those
dependencies are expected to be resolved during scheduling
insns but they can get skipped once we are skipping some
block while respecting sched_block debug counter.

For example, for the below test case:
--
int a, b, c, e, f;
float d;

void
g ()
{
  float h, i[1];
  for (; f;)
    if (c)
      {
	d *e;
	if (b)
	  {
	    float *j = i;
	    j[0] = 0;
	  }
	h = d;
      }
  if (h)
    a = i[0];
}
--
ICE occurs with option "-O2 -fdbg-cnt=sched_block:1".

As the discussion in [1], it seems that we think this debug
counter is useless and can be removed.  It's also implied
that if it's useful and used often, the above issue should
have been cared about and resolved earlier.  So this patch
is to remove this debug counter.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2023-November/635852.html

gcc/ChangeLog:

	* dbgcnt.def (sched_block): Remove.
	* sched-rgn.cc (schedule_region): Remove the support of debug count
	sched_block.
---
 gcc/dbgcnt.def   |  1 -
 gcc/sched-rgn.cc | 19 ++++++-------------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def
index 871cbf75d931..a8c4e61e13d5 100644
--- a/gcc/dbgcnt.def
+++ b/gcc/dbgcnt.def
@@ -198,7 +198,6 @@ DEBUG_COUNTER (pre_insn)
 DEBUG_COUNTER (prefetch)
 DEBUG_COUNTER (registered_jump_thread)
 DEBUG_COUNTER (sched2_func)
-DEBUG_COUNTER (sched_block)
 DEBUG_COUNTER (sched_breakdep)
 DEBUG_COUNTER (sched_func)
 DEBUG_COUNTER (sched_insn)
diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc
index e5964f54eadc..1c8acf5068a4 100644
--- a/gcc/sched-rgn.cc
+++ b/gcc/sched-rgn.cc
@@ -3198,20 +3198,13 @@ schedule_region (int rgn)
       current_sched_info->queue_must_finish_empty = current_nr_blocks == 1;
 
       curr_bb = first_bb;
-      if (dbg_cnt (sched_block))
-        {
-	  int saved_last_basic_block = last_basic_block_for_fn (cfun);
+      int saved_last_basic_block = last_basic_block_for_fn (cfun);
 
-	  schedule_block (&curr_bb, bb_state[first_bb->index]);
-	  gcc_assert (EBB_FIRST_BB (bb) == first_bb);
-	  sched_rgn_n_insns += sched_n_insns;
-	  realloc_bb_state_array (saved_last_basic_block);
-	  save_state_for_fallthru_edge (last_bb, curr_state);
-        }
-      else
-        {
-          sched_rgn_n_insns += rgn_n_insns;
-        }
+      schedule_block (&curr_bb, bb_state[first_bb->index]);
+      gcc_assert (EBB_FIRST_BB (bb) == first_bb);
+      sched_rgn_n_insns += sched_n_insns;
+      realloc_bb_state_array (saved_last_basic_block);
+      save_state_for_fallthru_edge (last_bb, curr_state);
 
       /* Clean up.  */
       if (current_nr_blocks > 1)
-- 
GitLab