https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128860
Bug ID: 128860
Summary: sched-rgn: debug-only block makes region size estimate
-1, -fcompare-debug failure with --param
max-sched-region-insns
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: yqtian668 at gmail dot com
Target Milestone: ---
Target: aarch64-unknown-linux-gnu
gcc.dg/torture/pr71802.c fails `-fcompare-debug` on aarch64 with:
```sh
aarch64-linux-gnu-gcc -O2 -fschedule-insns -w \
--param max-sched-extend-regions-iters=2 --param max-sched-region-insns=7 \
-fcompare-debug -S pr71802.c
```
```text
xgcc: error: pr71802.c: '-fcompare-debug' failure (length)
```
Tested with trunk e32f3d31e252d378450484b3a9250631d8efb36b. sched1 forms
different regions with -g, so one `mov w1, 3` is scheduled differently.
`rgn_estimate_number_of_insns` computes
`INSN_LUID (BB_END (bb)) - INSN_LUID (BB_HEAD (bb))` and then subtracts every
debug insn in the block. Notes get the LUID of the following insn, so for a
block that holds only a basic-block note and debug insns (bb 9 here: one
`var_location g (clobber)`), the result is -1 with -g but 0 for the same empty
block with -g0. More generally, debug insns at the end of a block that follow
a note are subtracted once too often. `too_large` therefore accepts a region
with -g that it rejects with -g0.
Ignoring trailing debug insns when choosing the end insn makes the estimate
match -g0 exactly; I have a patch.
I did not find a reproducer without the two `--param`s (scanned gcc.dg and
gcc.c-torture with -O2/-O3/-Os -fschedule-insns), and did not see it on
x86_64.