https://gcc.gnu.org/g:9d09d474b84bb93fea153ea0195800d550185496
commit r17-5111-g9d09d474b84bb93fea153ea0195800d550185496 Author: Yongqiang Tian <[email protected]> Date: Tue Oct 13 06:39:38 2026 -0600 [PATCH 1/2] reorg: Ignore debug insns in BARRIER checks [PR127808] relax_delay_slots checks whether a BARRIER immediately precedes a jump target at two sites. pass_cleanup_barriers can place a DEBUG_INSN between the BARRIER and CODE_LABEL, so prev_nonnote_insn makes both decisions depend on whether debug information is present. Use prev_nonnote_nondebug_insn for both queries. Add two SPARC tests covering the separate decisions. This follows up Jeff Law's review of the patch for PR127795, which pointed out that these BARRIER queries could potentially depend on DEBUG_INSN placement. I initially replied that I had not seen GCC put a DEBUG_INSN in that position. Further investigation showed that pass_cleanup_barriers can create exactly that sequence, so this patch corrects that earlier conclusion. Tested at GCC revision a02e2004cb707155d5b9b0a82dd428ded0ee2f6f: * Instrumented baseline runs confirm that the first and second SPARC tests reach the first and second modified queries, respectively. Both fail without this patch and pass with it. * A complete sparc-elf `make -k -j8 check-gcc` comparison has no regressions. * Native x86_64-pc-linux-gnu `make -j24 bootstrap` and `make -k -j24 check` completed with and without the two-patch series. After normalizing build paths, both produced the same outcomes: 621579 PASS, 6 FAIL, 1 XPASS, 4872 XFAIL, and 8114 UNSUPPORTED. * `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/127808 gcc/ChangeLog: * reorg.cc (relax_delay_slots): Ignore debug insns when looking for a BARRIER before a jump target. gcc/testsuite/ChangeLog: * gcc.target/sparc/reorg-relax-barrier-debug-1.c: New test. * gcc.target/sparc/reorg-relax-barrier-debug-2.c: New test. Signed-off-by: Yongqiang Tian <[email protected]> Diff: --- gcc/reorg.cc | 5 ++-- .../gcc.target/sparc/reorg-relax-barrier-debug-1.c | 27 ++++++++++++++++++++++ .../gcc.target/sparc/reorg-relax-barrier-debug-2.c | 27 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/gcc/reorg.cc b/gcc/reorg.cc index 1676bbe1f9ae..e5eaa303c2f0 100644 --- a/gcc/reorg.cc +++ b/gcc/reorg.cc @@ -3091,7 +3091,7 @@ relax_delay_slots (rtx_insn *first) && ! (next && switch_text_sections_between_p (jump_insn, next))) { rtx_insn *direct_label = as_a<rtx_insn *> (JUMP_LABEL (insn)); - rtx_insn *prev = prev_nonnote_insn (direct_label); + rtx_insn *prev = prev_nonnote_nondebug_insn (direct_label); /* If the insn jumps over a BARRIER and is the only way to reach its target, then we need to delete the BARRIER before the jump @@ -3338,7 +3338,8 @@ relax_delay_slots (rtx_insn *first) && !INSN_ANNULLED_BRANCH_P (delay_jump_insn) && !condjump_in_parallel_p (delay_jump_insn) && prev_active_insn (as_a<rtx_insn *> (target_label)) == insn - && !BARRIER_P (prev_nonnote_insn (as_a<rtx_insn *> (target_label)))) + && !BARRIER_P (prev_nonnote_nondebug_insn + (as_a<rtx_insn *> (target_label)))) { rtx_insn *after; int i; diff --git a/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-1.c b/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-1.c new file mode 100644 index 000000000000..f9deaec17c21 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-1.c @@ -0,0 +1,27 @@ +/* PR rtl-optimization/127808 */ +/* { dg-do compile } */ +/* { dg-require-effective-target label_values } */ +/* { dg-options "-O2 -fno-var-tracking -fcompare-debug" } */ + +/* relax_delay_slots must not let a debug insn between a BARRIER and a + jump target hide the BARRIER when it deletes the jump. */ + +void +foo (int b, int c) +{ + void *x = &&lab; + if (b < 5) + goto l2; +l1: + if (c < 0) + goto l1; +l2: + if (b) + { + lab: + __builtin_unreachable (); + } + if (c) + x = &&l1; + goto *x; +} diff --git a/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-2.c b/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-2.c new file mode 100644 index 000000000000..1226c3d44f21 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-relax-barrier-debug-2.c @@ -0,0 +1,27 @@ +/* PR rtl-optimization/127808 */ +/* { dg-do compile } */ +/* { dg-require-effective-target label_values } */ +/* { dg-options "-O1 -fno-var-tracking -fcompare-debug" } */ + +/* relax_delay_slots must not delete a filled jump to the following label + when a BARRIER and a debug insn separate the jump from that label. */ + +int h; + +void +foo (int b, int c) +{ + int i = b * 3; + void *x = &&lab; + if (b == 3) + goto l2; +lab: + __builtin_unreachable (); +l1: + while (b < i) + h = c; +l2: + if (c) + x = &&l1; + goto *x; +}
