| Message ID | 20261009123807.60177-1-yqtian668@gmail.com |
|---|---|
| State | Committed |
| Commit | 084169bfcc44a1dd249ca73ca8a606fcd2034dad |
| Headers |
Return-Path: <gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F1354BA2E05 for <patchwork@sourceware.org>; Fri, 9 Oct 2026 12:39:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F1354BA2E05 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=KoPVB1Aj X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id D9CA54BA5435 for <gcc-patches@gcc.gnu.org>; Fri, 9 Oct 2026 12:38:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9CA54BA5435 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D9CA54BA5435 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1030 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791549494; cv=none; b=lVOCuxR8tlairoUeQoHAHGNBQuAx0MQwKkGKgSaRO3/iWq7p/dZ3fXljQpRqMoYDCDl+y/7uF7lkqFpfr5f5RfKs1cBUvgL8/RUmCbA6HtlaAGG2M5/rBzEYdvYSFjhSv2tcuFpQrXrZgoCE/Oroh3JzAwL0Tz8aVXaJNzM2vAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791549494; c=relaxed/simple; bh=GnDVzadznOopy1TLQPnUXo0W+m2FPpNQaG9iJ3TPNNU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CyQSpizFKpXFXzXsYxeDbPbuDCDMg3VkH2M9AY2MDhsXhym+HA7c5nBIdndK6UDY9ssDtgRc5ewt/1d2ADTaxCNh3y2OZrlQ4pGXceFjwTEyoKSMziM5UgzidHQBlGyb69Lt27fG6+eeuoy/1AbA1Ao+TCEunhdvyaIE8K7XEFo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=KoPVB1Aj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9CA54BA5435 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-3a4cdc9025bso2815745a91.0 for <gcc-patches@gcc.gnu.org>; Fri, 09 Oct 2026 05:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791549493; x=1792154293; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=JKrrU/eR1ctK8GAWAmkhZ3xVSqcDs2haT+Wg5P5qfAw=; b=KoPVB1Aj+bFddwy3YQ5IfH/RT0g0z1EwtiyOWvD8nzR2OneGHJRrAllsl+XXONVAzr 2OLzGswHUdSDKgoS+5aD2yOCEwCnFzuSnyH2AYNi3+gqa/UTO5W6/Yx3GI8dclB2Cnbp G6T1xkY0rScFTHxFOXFGslVkU9U1izCVs+rLqZePrkUGB2l3Gal3t/4dnyBbY6PpYMzj c2450EYB8e2j/e5a3xOyrqDF7JusS3FI7hClfu+e0mYa7XrIVAYtnmh7Bf5iD7M/8DyO 34zP7FVcrrzHni5aD08zCLjvUKUoLBujSF6To9uenDlx7AuZVoBj/1ePHeC9yvDkq/GT OE/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791549493; x=1792154293; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=JKrrU/eR1ctK8GAWAmkhZ3xVSqcDs2haT+Wg5P5qfAw=; b=1YjV/jfum0cqFTjPRhe+rCAqZ2qONqJcad1GVQ53htQe51Rp11N39o5TOuO9rai48w GySxbcYyprjVg4xtijxaK1th7OrO87icIKTXFMgwWvHNDqLNa0gkGLQ5Jagcyc3MXZQK FWC1Gsw+GAXhy57rZQ8byXO0dN6Fht3QSi7nrCEzmuA1Lyoww2M4F/OppbfHom3A5+k8 q6Q6CCGi2UJ89wO+WHS8UCPb1mHt+FbGQuzfrEfq06xz9lU8Op8y/Glq5qoiWgNlqexh bqV7agS3Suxwsqa4Ycn3Sp8Cd5oNwIQV1Wzs12llW0XdqwramQM3MhbAOywnexXkzJSi S14g== X-Gm-Message-State: AFq9FYLWTSZd2m8DOegn6q5/LB6oJ+GW/z8B1EegxdUk/GkyT2SRuxl/ ECQuCCFwtAS/htQ+kTpHHLp7vMloOzuiXGsSS+dBv9eSxT1rmzTFqhK+WeaB/w== X-Gm-Gg: AYBFou3Yq1MV4YJ0EKbIMrEvTlqDW3oWHKL82O9S7stcGbjL+x8ICyX7Ibbjf3RvCUJ cqIvuPnzRdwSY1/RkzaGyW/sYgRlr+UnByilAxy3urVfuOi4R/alf9kYKzYOvQrFoFgrM4zGkPP iwZjbt9dH44MU+9KkJrUIKvrlMLTxZQ1P8C1YTHQuVO8y070AjaqtNSCOi2wnbpVXbkIR17U3dI Aj9EpbvLSNz1M1Bai7gbYBzt8D1ea745v06f7bp/aSazzwND7tYojxVAXtkjWpzrUte5/xRfT4q Lm6bwO0qEwwsKE4/n3ElZThXTAzB/J2qDwx0gr/wy6+u4/T7cRSHItHN/MYVW5vVJIKXGZM3Fzu 0uPh+L5t62DyKJykXEvw/XLRFXl5NTxa2bfLN4zQDPjie/aahwsOWjVb/e4tIMBcIoD5PuiomRU WpLXttzW/0LVZrPQIbJW/wIES8fIUeeP9lUsPmdbHU3V22pxo2KkdmdzvgnmQltAAlKhqGR8lUz ovR2SkptAoBj3g4Eg3xP9jKigtQLbzGrl1GAK3btYlWyUHGgOxBq6RrQ1uAM82KTYVPXCDmZQdN EmW6xcpWpLPhIYc7bj6sXj3lrMqo2A2RSy5eoFV3Lb5M748= X-Received: by 2002:a17:90b:1d03:b0:3a8:181a:2bfb with SMTP id 98e67ed59e1d1-3ab3a949a69mr1369563a91.23.1791549492501; Fri, 09 Oct 2026 05:38:12 -0700 (PDT) Received: from MU00187702X.tailf3e3b4.ts.net (n175-33-87-126.meb22.vic.optusnet.com.au. [175.33.87.126]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ab38b9633fsm4128693a91.6.2026.10.09.05.38.10 for <gcc-patches@gcc.gnu.org> (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 09 Oct 2026 05:38:12 -0700 (PDT) From: Yongqiang Tian <yqtian668@gmail.com> To: gcc-patches@gcc.gnu.org Subject: [PATCH] reorg: Ignore debug insns in delete_prior_computation [PR127795] Date: Fri, 9 Oct 2026 23:38:07 +1100 Message-ID: <20261009123807.60177-1-yqtian668@gmail.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GB_FREEMAIL_NUM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org |
| Series |
reorg: Ignore debug insns in delete_prior_computation [PR127795]
|
|
Commit Message
Yongqiang Tian
Oct. 9, 2026, 12:38 p.m. UTC
delete_prior_computation walks backward with prev_nonnote_insn while
deleting a dead computation. A DEBUG_INSN therefore terminates the scan
and can make -g retain an instruction that is deleted with -g0.
Use prev_nonnote_nondebug_insn for both steps of the walk. Add a SPARC
regression test that checks both -fcompare-debug and the absence of the
dead add.
Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian.
PR rtl-optimization/127795
gcc/ChangeLog:
* reorg.cc (delete_prior_computation): Ignore debug insns in the
backward scan.
gcc/testsuite/ChangeLog:
* gcc.target/sparc/reorg-delete-prior-debug.c: New test.
Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
---
gcc/reorg.cc | 4 ++--
.../sparc/reorg-delete-prior-debug.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/sparc/reorg-delete-prior-debug.c
Comments
On 10/9/26 6:38 AM, Yongqiang Tian wrote: > delete_prior_computation walks backward with prev_nonnote_insn while > deleting a dead computation. A DEBUG_INSN therefore terminates the scan > and can make -g retain an instruction that is deleted with -g0. > > Use prev_nonnote_nondebug_insn for both steps of the walk. Add a SPARC > regression test that checks both -fcompare-debug and the absence of the > dead add. > > Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian. > > PR rtl-optimization/127795 > > gcc/ChangeLog: > > * reorg.cc (delete_prior_computation): Ignore debug insns in the > backward scan. > > gcc/testsuite/ChangeLog: > > * gcc.target/sparc/reorg-delete-prior-debug.c: New test. > > Signed-off-by: Yongqiang Tian <yqtian668@gmail.com> Thanks. Given the patch to the compiler proper is trivial from a copyright standpoint it doesn't matter if it was LLM generated or not. For future patches please note how the patch was tested. Normally a patch to the generic part of the compiler would require a bootstrap and regression test on one of the primary targets such as x86 or aarch64. reorg.cc is pretty narrow and only used on a small number of targets and wouldn't be exercised during an x86 or aarch64 build. A bootstrap and regression test on sparc would be best, but that may not be generally feasible. I'm not set up for sparc testing (though there's no inherent reason why I couldn't set that up again....) As a quick proxy, I tested this on crosses that use delay slots. In particular, sh3, sh3eb, or1k, visium, microblaze, iq2000, fr30, cris, and arc with no regressions. So I'm confident it's behaving reasonably. hppa, sh4, sh4eb will give this deeper testing over the coming days. Your other patch fixes similar problems elsewhere in reorg.cc, I'll look at that patch shortly. LLM review indicates there are two similar kinds of instances that show up in reorg.c. In particular the BARRIER checks in relax_delay_slots could potentially lead to a -fcompare-debug fail, but they'd probably need to be deeply evaluated to determine if a DEBUG_INSN could appear at that particular point in the IL. I'll push this to the trunk momentarily. Thanks! jeff
On 10/9/26, Jeff Law wrote: > For future patches please note how the patch was tested. Thanks for testing it on the delay-slot crosses and for pushing it. Sorry for leaving that out. For this patch: - I completed a native x86_64-pc-linux-gnu bootstrap and full make -k check at master 54e232d0d4752b419ed775bdad50d83798fa899d, both with and without the patch. After normalizing the build-directory path embedded in one module test name, both runs produced the same 541,492 result records. As you noted, this does not exercise reorg.cc. - sparc-elf cross: the new gcc.target/sparc/reorg-delete-prior-debug.c fails without the patch and passes with it. - contrib/check_GNU_style.sh is clean. I will include the testing in future submissions, and for reorg.cc changes I will add a run of the sparc-elf cross testsuite. > In particular the BARRIER checks in relax_delay_slots could > potentially lead to a -fcompare-debug fail, but they'd probably need > to be deeply evaluated to determine if a DEBUG_INSN could appear at > that particular point in the IL. I also found those when auditing reorg.cc. The prev_nonnote_insn (label) BARRIER tests would only change if a DEBUG_INSN sat between a BARRIER and the following CODE_LABEL, and I have not seen GCC put one there. Thus I did not open a bug report for this. I can also take a second look tomorrow. Again, thanks a lot for looking at this. Thanks, Yongqiang On Sat, 10 Oct 2026 at 00:51, Jeff Law <jeffrey.law@oss.qualcomm.com> wrote: > > > > On 10/9/26 6:38 AM, Yongqiang Tian wrote: > > delete_prior_computation walks backward with prev_nonnote_insn while > > deleting a dead computation. A DEBUG_INSN therefore terminates the scan > > and can make -g retain an instruction that is deleted with -g0. > > > > Use prev_nonnote_nondebug_insn for both steps of the walk. Add a SPARC > > regression test that checks both -fcompare-debug and the absence of the > > dead add. > > > > Assisted-by: OpenAI Codex 5.6 Sol, co-reviewed by Claude and Yongqiang Tian. > > > > PR rtl-optimization/127795 > > > > gcc/ChangeLog: > > > > * reorg.cc (delete_prior_computation): Ignore debug insns in the > > backward scan. > > > > gcc/testsuite/ChangeLog: > > > > * gcc.target/sparc/reorg-delete-prior-debug.c: New test. > > > > Signed-off-by: Yongqiang Tian <yqtian668@gmail.com> > Thanks. Given the patch to the compiler proper is trivial from a > copyright standpoint it doesn't matter if it was LLM generated or not. > > For future patches please note how the patch was tested. Normally a > patch to the generic part of the compiler would require a bootstrap and > regression test on one of the primary targets such as x86 or aarch64. > reorg.cc is pretty narrow and only used on a small number of targets and > wouldn't be exercised during an x86 or aarch64 build. A bootstrap and > regression test on sparc would be best, but that may not be generally > feasible. I'm not set up for sparc testing (though there's no inherent > reason why I couldn't set that up again....) > > As a quick proxy, I tested this on crosses that use delay slots. In > particular, sh3, sh3eb, or1k, visium, microblaze, iq2000, fr30, cris, > and arc with no regressions. So I'm confident it's behaving > reasonably. hppa, sh4, sh4eb will give this deeper testing over the > coming days. > > Your other patch fixes similar problems elsewhere in reorg.cc, I'll look > at that patch shortly. LLM review indicates there are two similar kinds > of instances that show up in reorg.c. In particular the BARRIER checks > in relax_delay_slots could potentially lead to a -fcompare-debug fail, > but they'd probably need to be deeply evaluated to determine if a > DEBUG_INSN could appear at that particular point in the IL. > > I'll push this to the trunk momentarily. > > Thanks! > > jeff
diff --git a/gcc/reorg.cc b/gcc/reorg.cc index 76b3e1438..38aad68d7 100644 --- a/gcc/reorg.cc +++ b/gcc/reorg.cc @@ -2884,10 +2884,10 @@ delete_prior_computation (rtx note, rtx_insn *insn) rtx_insn *our_prev; rtx reg = XEXP (note, 0); - for (our_prev = prev_nonnote_insn (insn); + for (our_prev = prev_nonnote_nondebug_insn (insn); our_prev && (NONJUMP_INSN_P (our_prev) || CALL_P (our_prev)); - our_prev = prev_nonnote_insn (our_prev)) + our_prev = prev_nonnote_nondebug_insn (our_prev)) { rtx pat = PATTERN (our_prev); diff --git a/gcc/testsuite/gcc.target/sparc/reorg-delete-prior-debug.c b/gcc/testsuite/gcc.target/sparc/reorg-delete-prior-debug.c new file mode 100644 index 000000000..b1992bd96 --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/reorg-delete-prior-debug.c @@ -0,0 +1,19 @@ +/* PR rtl-optimization/127795 */ + +/* Verify that delay-slot reorganization deletes the dead add with and + without debug information. -fno-tree-ter keeps the add separate, while + -fno-var-tracking keeps the debug marker until the dbr pass. Falling off + the end of the function is required to expose the deletion path. */ + +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-ter -fno-var-tracking -fcompare-debug" } */ + +int +foo (int a, int b) +{ + int e = a + b; + if (e >= 97) + return a; +} + +/* { dg-final { scan-assembler-not "add\t%" } } */