https://gcc.gnu.org/g:50fa5ffebbd6dc02dd045fff75923a5409d9f169
commit r17-6602-g50fa5ffebbd6dc02dd045fff75923a5409d9f169 Author: Yongqiang Tian <[email protected]> Date: Mon Nov 23 09:15:30 2026 -0700 [PATCH v2] sched-rgn: Count non-debug insns in region size estimate [PR128860] rgn_estimate_number_of_insns used the LUID span of a block and then subtracted the debug insns in it. Notes take the LUID of the following insn, so when the last non-debug element of a block is a note, the debug insns after it were subtracted once too often. A block with only debug insns was counted as -1 insns with -g and 0 with -g0, and too_large could accept a region with -g only. Count the non-debug insns directly instead. The exact count is normally one greater than the previous LUID-span estimate, so this also increases the -g0 estimate by one for most blocks. Regression tested on an aarch64-linux-gnu cross compiler (c, c++) with binutils and glibc, running execution tests under qemu-user. No existing test result changed; the patched tree additionally passes the new test. Assisted-by: Claude Opus 5.5, co-reviewed by OpenAI Codex 5.6 Sol and Yongqiang Tian. --- v2: Count non-debug insns directly, as suggested by Richard. I also logged every call to estimate_number_of_insns while compiling the 13,579 files in gcc.dg, gcc.dg/torture, and gcc.c-torture on the aarch64-linux-gnu cross: Calls Blocks Maximum -O2 -fschedule-insns 14,022 14,022 1 -O3 -funroll-loops -fschedule-insns 11,491 11,491 1 -O2, region extension, 2 iterations 64,714 59,022 2 -O3, region extension, 10 iterations 68,828 63,718 2 Without region extension, every block was estimated exactly once. With region extension enabled, some blocks were estimated twice: once in find_rgns and once when extend_rgns assembled the extended regions. No block was estimated more than twice in this corpus. The largest run averaged about 1.08 calls per block, so a cache does not appear worthwhile for this workload. I also compared the -g0 assembly before and after v2 over the same corpus: -O2 -fschedule-insns 0 differences -O3 -funroll-loops -fschedule-insns 1 difference -O2 with the test's region-extension parameters 437 differences The single -O3 difference is gcc.c-torture/compile/pr86637-2.c. The test parameters deliberately put the region-size limit at the boundary exposed by the bug. With those parameters, -fcompare-debug fails on pr71802.c before the change and passes after it, with no remaining failure in the corpus. The full aarch64-linux-gnu cross testsuite, including execution tests under qemu-user, produced: gcc PASS gcc FAIL g++ PASS g++ FAIL base 407898 133 473659 8 v2 407899 133 473659 8 The sorted gcc.sum and g++.sum result lines differ only by the new gcc.dg/pr128860.c PASS. PR rtl-optimization/128860 gcc/ChangeLog: * sched-rgn.cc (rgn_estimate_number_of_insns): Count the non-debug insns instead of using the LUID span. gcc/testsuite/ChangeLog: * gcc.dg/pr128860.c: New test. Signed-off-by: Yongqiang Tian <[email protected]> Diff: --- gcc/sched-rgn.cc | 16 +++++----------- gcc/testsuite/gcc.dg/pr128860.c | 8 ++++++++ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gcc/sched-rgn.cc b/gcc/sched-rgn.cc index 08af28bcd74d..246d4dbf419a 100644 --- a/gcc/sched-rgn.cc +++ b/gcc/sched-rgn.cc @@ -547,18 +547,12 @@ find_single_block_region (bool ebbs_p) static int rgn_estimate_number_of_insns (basic_block bb) { - int count; - - count = INSN_LUID (BB_END (bb)) - INSN_LUID (BB_HEAD (bb)); - - if (MAY_HAVE_DEBUG_INSNS) - { - rtx_insn *insn; + int count = 0; + rtx_insn *insn; - FOR_BB_INSNS (bb, insn) - if (DEBUG_INSN_P (insn)) - count--; - } + FOR_BB_INSNS (bb, insn) + if (NONDEBUG_INSN_P (insn)) + count++; return count; } diff --git a/gcc/testsuite/gcc.dg/pr128860.c b/gcc/testsuite/gcc.dg/pr128860.c new file mode 100644 index 000000000000..51fac7ddf6b1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr128860.c @@ -0,0 +1,8 @@ +/* PR rtl-optimization/128860 */ +/* The region size estimate must not depend on debug insns. A block that + contains only debug insns used to be counted as -1 insns with -g. */ +/* { dg-do compile } */ +/* { dg-require-effective-target scheduling } */ +/* { dg-options "-O2 -fschedule-insns -fcompare-debug -w --param max-sched-extend-regions-iters=2 --param max-sched-region-insns=7" } */ + +#include "torture/pr71802.c"
