https://gcc.gnu.org/g:0eea1e39af146d98d8bce3d93ede34ea13196899
commit r17-4467-g0eea1e39af146d98d8bce3d93ede34ea13196899 Author: Yongqiang Tian <[email protected]> Date: Fri Sep 18 23:03:54 2026 +1000 pru: Ignore debug insns when padding repeat loops [PR127460] pru_insert_loop_label_last walks backward over the final two opcodes of a repeat loop to determine how much padding to add. INSN_P also accepts debug instructions, so a surviving DEBUG_INSN can be treated as an unrecognized opcode and stop the walk early. This causes the function to add an extra NOP. Use NONDEBUG_INSN_P so debug instructions do not affect the opcode count. Add a regression test for the extra padding observed with -g -fno-var-tracking. Tested for pru-unknown-elf. The new test fails before the fix and passes after it. The complete PRU testsuite has no new failures. Also bootstrapped and regression-tested on x86_64-pc-linux-gnu with no new failures. gcc/ChangeLog: PR target/127460 * config/pru/pru.cc (pru_insert_loop_label_last): Ignore debug instructions while counting final loop opcodes. gcc/testsuite/ChangeLog: PR target/127460 * gcc.target/pru/pr127460.c: New test. Signed-off-by: Yongqiang Tian <[email protected]> Diff: --- gcc/config/pru/pru.cc | 2 +- gcc/testsuite/gcc.target/pru/pr127460.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/config/pru/pru.cc b/gcc/config/pru/pru.cc index 01e703942469..80101b0f1a9b 100644 --- a/gcc/config/pru/pru.cc +++ b/gcc/config/pru/pru.cc @@ -2560,7 +2560,7 @@ pru_insert_loop_label_last (rtx_insn *last_insn, rtx_code_label *label, if (code == CALL_INSN || code == CODE_LABEL || code == BARRIER) break; - if (INSN_P (prev)) + if (NONDEBUG_INSN_P (prev)) { if (GET_CODE (PATTERN (prev)) == SEQUENCE) prev = as_a <rtx_insn *> (XVECEXP (PATTERN (prev), 0, 1)); diff --git a/gcc/testsuite/gcc.target/pru/pr127460.c b/gcc/testsuite/gcc.target/pru/pr127460.c new file mode 100644 index 000000000000..eba621b9aff7 --- /dev/null +++ b/gcc/testsuite/gcc.target/pru/pr127460.c @@ -0,0 +1,20 @@ +/* Verify that debug instructions do not affect repeat-loop padding. */ + +/* { dg-options "-O1 -mloop -g -fno-var-tracking" } */ + +unsigned int +test_loop (unsigned int n, unsigned int x) +{ + unsigned int i; + + if (n >= 0x10000) + return 0; + if (!n) + return 0; + + /* { dg-final { scan-assembler "loop\\t.L\[0-9\]*, r\[0-9\]*" } } */ + /* { dg-final { scan-assembler-times {\tnop} 1 } } */ + for (i = 0; i < n; i++) + x <<= 2; + return x; +}
