https://gcc.gnu.org/g:125d0919fa1c22925cb346ebf48f51ec3f7ca8d2

commit r17-5196-g125d0919fa1c22925cb346ebf48f51ec3f7ca8d2
Author: Yongqiang Tian <[email protected]>
Date:   Wed Oct 14 07:20:45 2026 -0600

    resource: Ignore debug insns in find_basic_block [PR127726]
    
    find_basic_block walks backward toward a BARRIER with a bounded search.
    prev_nonnote_insn returns DEBUG_INSNs, so debug markers consume the
    max-delay-slot-live-search budget.  Exhausting the budget makes
    mark_target_live_regs treat every register as live and can prevent an
    ordinary instruction from filling a delay slot.
    
    The forward label scan has the same debug dependence.  This issue was
    already tracked as PR127726.  Jeff Law also suggested auditing
    find_basic_block while reviewing the PR127808 patch.  This patch uses the
    nondebug neighbour helpers in both walks and adds a focused SPARC test
    whose live-search budget is just large enough without its debug marker.
    
    Tested at GCC revision ca33fb40100211b9ed8c2e686b46cb9025791930:
    
    * The new test fails without the patch with an -fcompare-debug length
      mismatch and passes with the patch on sparc-elf and mips-elf.
    * A complete sparc-elf sparc.exp comparison has no regressions; the only
      difference is the new test changing from absent to PASS.
    * Native x86_64-pc-linux-gnu bootstrap and full regression testing
      completed for the baseline and the exact patch.  Both produced 530002
      PASS, 9 FAIL, 1 XPASS, 4292 XFAIL, and 7556 UNSUPPORTED results, with
      identical unexpected-result sets.
    * contrib/check_GNU_style.sh and git diff --check pass.
    
    Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian.
    
            PR rtl-optimization/127726
    
    gcc/ChangeLog:
    
            * resource.cc (find_basic_block): Ignore debug instructions in
            the backward and forward scans.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/sparc/resource-live-search-debug.c: New test.

Diff:
---
 gcc/resource.cc                                    |  8 ++---
 .../gcc.target/sparc/resource-live-search-debug.c  | 35 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/gcc/resource.cc b/gcc/resource.cc
index bf8bc7131800..60104caff76c 100644
--- a/gcc/resource.cc
+++ b/gcc/resource.cc
@@ -130,9 +130,9 @@ find_basic_block (rtx_insn *insn, int search_limit)
 {
   /* Scan backwards to the previous BARRIER.  Then see if we can find a
      label that starts a basic block.  Return the basic block number.  */
-  for (insn = prev_nonnote_insn (insn);
+  for (insn = prev_nonnote_nondebug_insn (insn);
        insn && !BARRIER_P (insn) && search_limit != 0;
-       insn = prev_nonnote_insn (insn), --search_limit)
+       insn = prev_nonnote_nondebug_insn (insn), --search_limit)
     ;
 
   /* The closest BARRIER is too far away.  */
@@ -145,9 +145,9 @@ find_basic_block (rtx_insn *insn, int search_limit)
 
   /* See if any of the upcoming CODE_LABELs start a basic block.  If we reach
      anything other than a CODE_LABEL or note, we can't find this code.  */
-  for (insn = next_nonnote_insn (insn);
+  for (insn = next_nonnote_nondebug_insn (insn);
        insn && LABEL_P (insn);
-       insn = next_nonnote_insn (insn))
+       insn = next_nonnote_nondebug_insn (insn))
     if (BLOCK_FOR_INSN (insn))
       return BLOCK_FOR_INSN (insn)->index;
 
diff --git a/gcc/testsuite/gcc.target/sparc/resource-live-search-debug.c 
b/gcc/testsuite/gcc.target/sparc/resource-live-search-debug.c
new file mode 100644
index 000000000000..b994c3e9521b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/sparc/resource-live-search-debug.c
@@ -0,0 +1,35 @@
+/* PR rtl-optimization/127726 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-var-tracking -fcompare-debug 
--param=max-delay-slot-live-search=4" } */
+
+/* Keep debug markers as DEBUG_INSNs through delay-slot reorg.  The
+   live-search budget is just large enough without the marker below.  */
+
+extern int g[64];
+extern int h (int);
+
+int
+f0 (int a, int b, int c)
+{
+  int x = a;
+  int y = b;
+  int z = c;
+  int t;
+
+  if (a > 0)
+    {
+      t = a;
+      x = h (x);
+      y += 3;
+    }
+  else
+    {
+      z = z - x;
+      g[57] = z;
+      y = y | c;
+      x = x + a;
+    }
+  if (y == 0)
+    z = h (z) + x;
+  return x + y * z;
+}

Reply via email to