reorg: Ignore debug insns in neighboring-insn lookups [PR127725]
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap |
success
|
Build passed
|
Commit Message
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 <yqtian668@gmail.com>
---
gcc/reorg.cc | 6 ++--
.../sparc/reorg-fill-slots-regcopy-debug.c | 29 +++++++++++++++++++
.../sparc/reorg-get-label-before-debug.c | 13 +++++++++
.../sparc/reorg-optimize-skip-debug.c | 10 +++++++
4 files changed, 55 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/sparc/reorg-fill-slots-regcopy-debug.c
create mode 100644 gcc/testsuite/gcc.target/sparc/reorg-get-label-before-debug.c
create mode 100644 gcc/testsuite/gcc.target/sparc/reorg-optimize-skip-debug.c
Comments
On 10/9/26 4:46 AM, Yongqiang Tian wrote:
> 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 <yqtian668@gmail.com>
Thanks. I did the same testing as the prior reorg patch and it's clean.
This isn't significant from a copyright standpoint, even when aggregated
with the prior patch, so if the code was LLM generated, we're still OK
from a policy standpoint. I've pushed this to the trunk.
Thanks again,
jeff
@@ -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
new file mode 100644
@@ -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;
+ }
+}
new file mode 100644
@@ -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];
+}
new file mode 100644
@@ -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;
+}