https://gcc.gnu.org/g:484a3f0c5f56accdc7a9c2dca3f1835d5439d5ff
commit r17-5028-g484a3f0c5f56accdc7a9c2dca3f1835d5439d5ff Author: Yongqiang Tian <[email protected]> Date: Fri Oct 9 08:48:22 2026 -0600 [PATCH] reorg: Ignore debug insns in neighboring-insn lookups [PR127725] The delay-slot reorganization pass uses note-skipping neighboring-insn lookups in three places where a DEBUG_INSN is not an executable boundary. As a result, debug information can change skip optimization, label reuse, and register-copy recognition. Use the nondebug lookup helpers and add focused SPARC -fcompare-debug tests for all three paths. Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian. PR rtl-optimization/127725 gcc/ChangeLog: * reorg.cc (optimize_skip): Use next_nonnote_nondebug_insn. (get_label_before): Use prev_nonnote_nondebug_insn. (fill_slots_from_thread): Use next_nonnote_nondebug_insn. gcc/testsuite/ChangeLog: * gcc.target/sparc/reorg-fill-slots-regcopy-debug.c: New test. * gcc.target/sparc/reorg-get-label-before-debug.c: New test. * gcc.target/sparc/reorg-optimize-skip-debug.c: New test. Signed-off-by: Yongqiang Tian <[email protected]> Diff: --- gcc/reorg.cc | 6 ++--- .../sparc/reorg-fill-slots-regcopy-debug.c | 29 ++++++++++++++++++++++ .../sparc/reorg-get-label-before-debug.c | 13 ++++++++++ .../gcc.target/sparc/reorg-optimize-skip-debug.c | 10 ++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/gcc/reorg.cc b/gcc/reorg.cc index 38aad68d78a5..1676bbe1f9ae 100644 --- a/gcc/reorg.cc +++ b/gcc/reorg.cc @@ -670,7 +670,7 @@ note_delay_statistics (int slots_filled, int index) static void optimize_skip (rtx_jump_insn *insn, vec<rtx_insn *> *delay_list) { - rtx_insn *trial = next_nonnote_insn (insn); + rtx_insn *trial = next_nonnote_nondebug_insn (insn); rtx_insn *next_trial = next_active_insn (trial); int flags; @@ -1765,7 +1765,7 @@ get_label_before (rtx_insn *insn, rtx sibling) /* Find an existing label at this point or make a new one if there is none. */ - label = prev_nonnote_insn (insn); + label = prev_nonnote_nondebug_insn (insn); if (label == 0 || !LABEL_P (label)) { @@ -2580,7 +2580,7 @@ fill_slots_from_thread (rtx_jump_insn *insn, rtx condition, && REG_P (SET_DEST (pat)) && !reg_overlap_mentioned_p (SET_DEST (pat), SET_SRC (pat))) { - rtx_insn *next = next_nonnote_insn (trial); + rtx_insn *next = next_nonnote_nondebug_insn (trial); if (next && NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) != USE diff --git a/gcc/testsuite/gcc.target/sparc/reorg-fill-slots-regcopy-debug.c b/gcc/testsuite/gcc.target/sparc/reorg-fill-slots-regcopy-debug.c new file mode 100644 index 000000000000..e23ae1ee1301 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-fill-slots-regcopy-debug.c @@ -0,0 +1,29 @@ +/* PR rtl-optimization/127725 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v8 -fno-var-tracking -fcompare-debug --param=max-delay-slot-live-search=100000 --param=max-delay-slot-insn-search=100000" } */ + +int h (int); + +int +f (void) +{ + unsigned int mid; + unsigned int lo = 0; + unsigned int hi = 3; + unsigned int last = -1; + + for (;;) + { + mid = (lo + hi) / 2; + if (last == mid) + return 0; + last = mid; + int r = h (mid); + if (r < 0) + hi = mid; + else if (r > 0) + lo = mid; + else + return 1; + } +} diff --git a/gcc/testsuite/gcc.target/sparc/reorg-get-label-before-debug.c b/gcc/testsuite/gcc.target/sparc/reorg-get-label-before-debug.c new file mode 100644 index 000000000000..ce241f5dc2d5 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-get-label-before-debug.c @@ -0,0 +1,13 @@ +/* PR rtl-optimization/127725 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v8 -fno-var-tracking -fcompare-debug --param=max-delay-slot-live-search=100000 --param=max-delay-slot-insn-search=100000" } */ + +int b; + +void +foo (int n, char *c) +{ + for (;;) + for (int f = 0; f < n; f++) + b = c[f]; +} diff --git a/gcc/testsuite/gcc.target/sparc/reorg-optimize-skip-debug.c b/gcc/testsuite/gcc.target/sparc/reorg-optimize-skip-debug.c new file mode 100644 index 000000000000..ebd6a18fb1a1 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-optimize-skip-debug.c @@ -0,0 +1,10 @@ +/* PR rtl-optimization/127725 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcpu=v8 -fno-var-tracking -fcompare-debug --param=max-delay-slot-live-search=100000 --param=max-delay-slot-insn-search=100000" } */ + +void +f (int a, int b, int *p) +{ + if (a > b) + *p = b; +}
