From patchwork Wed Jul 10 05:15:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1958708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WJmK86YMYz1yNy for ; Wed, 10 Jul 2024 15:15:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D98F63870912 for ; Wed, 10 Jul 2024 05:15:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 10E673865C21 for ; Wed, 10 Jul 2024 05:15:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10E673865C21 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 10E673865C21 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720588521; cv=none; b=nbMe+Qt8yTza/A/2JVR6GySWudbzex2eKQ/6ggtwaHMID/6QWJX4zwVdfZbCh9mQ0yG0iLhePE1S4A769Ai+tF3FVR6xuW1EAlIuBb2Od/YFBoGCAKtnMtvnHr8Efdg3F5BkWNv6aCbpT/OCfmM+bcHLio//eM6WedxI28tnQLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720588521; c=relaxed/simple; bh=VATvYv8suz3A62Rduxl0CRsHyWDuDwWLf+5eJx7jQ4o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=E3J4OVOJGn85ywYr/iVMDQrxg40alaNzVGAfUSQEt2qHIcw1Uni29xjWkTT95MYZJh7eRqqcMFPBei3Cl1/Kk4OZxe2ZXSGETdDmqCX9RspxpdoXU87y2h7LUUUYd9V/fXK15BNULOZZCZ/tGC8wXfGSM7TmEphp5GnJ3rtJEBo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5927D113E for ; Tue, 9 Jul 2024 22:15:43 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A678E3F766 for ; Tue, 9 Jul 2024 22:15:17 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] recog: Avoid validate_change shortcut for groups [PR115782] Date: Wed, 10 Jul 2024 06:15:16 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Spam-Status: No, score=-19.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org In this PR, due to the -f flags, we ended up with: bb1: r10=r10 ... bb2: r10=r10 ... bb3: ...=r10 with bb1->bb2 and bb1->bb3. late-combine successfully combined the bb1->bb2 def-use and set the insn code to NOOP_MOVE_INSN_CODE. The bb1->bb3 combination then failed for... reasons. At this point, everything should have been rewound to its original state. However, substituting r10=r10 into r10=r10 gives r10=r10, and validate_change had an early-out for no-op rtl changes. This meant that validate_change did not register a change for the bb2 insn and so did not save its old insn code. The NOOP_MOVE_INSN_CODE therefore persisted even after the attempt had been rewound. IMO it'd be too cumbersome and error-prone to expect all users of validate_change to be aware of this possibility. If code is using validate_change with in_group=1, I think it has a reasonable expectation that a change will be registered and that the insn code will be saved (and restored on cancel). This patch therefore limits the shortcut to the !in_group case. Bootstrapped & regression-tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install? Richard gcc/ PR rtl-optimization/115782 * recog.cc (validate_change_1): Suppress early exit for no-op changes that are part of a group. gcc/testsuite/ PR rtl-optimization/115782 * gcc.dg/pr115782.c: New test. --- gcc/recog.cc | 7 ++++++- gcc/testsuite/gcc.dg/pr115782.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr115782.c diff --git a/gcc/recog.cc b/gcc/recog.cc index 36507f3f57c..7710c55b745 100644 --- a/gcc/recog.cc +++ b/gcc/recog.cc @@ -230,7 +230,12 @@ validate_change_1 (rtx object, rtx *loc, rtx new_rtx, bool in_group, new_len = -1; } - if ((old == new_rtx || rtx_equal_p (old, new_rtx)) + /* When a change is part of a group, callers expect to be able to change + INSN_CODE after making the change and have the code reset to its old + value by a later cancel_changes. We therefore need to register group + changes even if they're no-ops. */ + if (!in_group + && (old == new_rtx || rtx_equal_p (old, new_rtx)) && (new_len < 0 || XVECLEN (new_rtx, 0) == new_len)) return true; diff --git a/gcc/testsuite/gcc.dg/pr115782.c b/gcc/testsuite/gcc.dg/pr115782.c new file mode 100644 index 00000000000..f4d11cc6d0f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr115782.c @@ -0,0 +1,23 @@ +// { dg-require-effective-target lp64 } +// { dg-options "-O2 -fno-guess-branch-probability -fgcse-sm -fno-expensive-optimizations -fno-gcse" } + +int printf(const char *, ...); +int a, b, c, d, e, f, g, i, j, m, h; +long k, l, n, o; +int main() { + int p = e, r = i << a, q = r & b; + k = 4073709551613; + l = m = c = -(c >> j); + d = g ^ h ^ 4073709551613; + n = q - h; + o = ~d; + f = c * 4073709551613 / 409725 ^ r; + if ((n && m) || (q && j) || a) + return 0; + d = o | p; + if (g) + printf("0"); + d = p; + c++; + return 0; +}