From patchwork Tue Oct 24 10:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 157378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1852934vqx; Tue, 24 Oct 2023 03:51:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLfvNcbGvxO2H+bsSZRAsjt+xV3TvofX725nT1Oxsuc/P6SKB2kPpu2qxwAzBCtZStQo83 X-Received: by 2002:a05:622a:1a92:b0:41e:204b:f953 with SMTP id s18-20020a05622a1a9200b0041e204bf953mr5261711qtc.64.1698144708621; Tue, 24 Oct 2023 03:51:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698144708; cv=pass; d=google.com; s=arc-20160816; b=ni44KTEn6i2bXfCQ8vaHLqB2kQJW58QLGEnAOBsyfvpmuBV1X6g7tBKizpVbX+uMf8 rlR65R2sDF4A4qOpBA3hipVGxSRpVuGt+O37/cNGBWdJcDxmVkvb0/xMI/5EZRJ0MfiV 81osjrdXm6rPZIAwMbZPQt6/itMgFvY67cNPcZERCGApZlcuo28mm1As27JJQBoL8YMD Bp+V5/CDMSZgIgM65Dm1za1MNaJWDBJ8yVLBKks+65pvmD8IceVUiDo7CDNe3+HZWJiS XSlRTRWylJX/Vl5M89DJ4a/XdD9pupPgsAz1CtKHtF19GC8Wkk0ZUEyMZg1GKjyoZ5Cn orMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:arc-filter:dmarc-filter:delivered-to; bh=K7sZrf9V7ARZIeL9VUdw479okA4ElN6qiNQwRSroTgQ=; fh=WSfZ840Wi6BqtTz8VZjapJ1yCCJ9QRCfxSVxwOS9rLc=; b=pkYX7EVdgBBFIY0cd6SMZulf6F53UYB2Xj/wNaQ9QEQ0W/MDINV64YMkiTL7BjGNDW Pg5vEgTluAph8Ky5r9NlQx7O9h1ccAyJwrpMYrllE6/7KxyisJxPcHeGFAPnJmaLUtgn 0S/8kU5g1QMrxqYdErVWrfiuQx7y2B2kPhlojgofyaf4P3yY9JSU7WwwCJsbyzUMGgcm xZTlHRERcnSan0i9bh0bgLMvipgWrumtjjEaXn54zUGAxmhFxRJNA1IPiEhc1ZfVpeuZ UEmjAy7AzrVcA0h2xQDxZEgWhDh0KJq2JoOPVgUMVDI6dweXjVLU15SbBXEq1keSd3Bi BYWQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f9-20020ac85d09000000b0041819ed7676si6812270qtx.162.2023.10.24.03.51.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 03:51:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C1C3385700D for ; Tue, 24 Oct 2023 10:51:34 +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 C97D83857706 for ; Tue, 24 Oct 2023 10:50:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C97D83857706 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 C97D83857706 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=1698144654; cv=none; b=F4i/obNbXd3/ssZawFvd2lufuvmGSlyIINLez3AcpvmVAK8FiFPHGwQbaAC7jJPQrWebqLd/qV4wbPNt5G22bsAEn+XDoCXeKTaIW/pBNdy7JF/4fPpHs1NCtwARAxjiqwY8C4RynbCRVdEuRLmm8GZ46WNA+ECEKsz1V5162ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698144654; c=relaxed/simple; bh=vs5CnsvUssbczkN8ohHT5iQuKdGXMiecWAGsMbmPSDw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=EwuGmdNrLheyg/1PaVNTsjRuFJcul0UolLztx4D7u1T5UWW+qWVQMPd+Ojm/ht5I+2deI14Ll+dDxFO8BqFt29g207m7BURfsvrZ7bD1RCepFIpWI0vKGwdyGaazlG0j4SaHeAV2XPxFidq13E5X9W0HxJTe8M8mSJu56QUdhXk= 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 752F4C15; Tue, 24 Oct 2023 03:51:24 -0700 (PDT) Received: from e121540-lin.manchester.arm.com (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DBCC73F64C; Tue, 24 Oct 2023 03:50:42 -0700 (PDT) From: Richard Sandiford To: jlaw@ventanamicro.com, gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 4/6] rtl-ssa: Handle artifical uses of deleted defs Date: Tue, 24 Oct 2023 11:50:04 +0100 Message-Id: <20231024105006.3337671-5-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231024105006.3337671-1-richard.sandiford@arm.com> References: <20231024105006.3337671-1-richard.sandiford@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-23.9 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780633785939249076 X-GMAIL-MSGID: 1780633785939249076 If an optimisation removes the last real use of a definition, there can still be artificial uses left. This patch removes those uses too. These artificial uses exist because RTL-SSA is only an SSA-like view of the existing RTL IL, rather than a native SSA representation. It effectively treats RTL registers like gimple vops, but with the addition of an RPO view of the register's lifetime(s). Things are structured to allow most operations to update this RPO view in amortised sublinear time. gcc/ * rtl-ssa/functions.h (function_info::process_uses_of_deleted_def): New member function. * rtl-ssa/functions.cc (function_info::process_uses_of_deleted_def): Likewise. (function_info::change_insns): Use it. --- gcc/rtl-ssa/changes.cc | 35 +++++++++++++++++++++++++++++++++-- gcc/rtl-ssa/functions.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc index 5800f9dba97..3e14069421c 100644 --- a/gcc/rtl-ssa/changes.cc +++ b/gcc/rtl-ssa/changes.cc @@ -209,6 +209,35 @@ rtl_ssa::changes_are_worthwhile (array_slice changes, return true; } +// SET has been deleted. Clean up all remaining uses. Such uses are +// either dead phis or now-redundant live-out uses. +void +function_info::process_uses_of_deleted_def (set_info *set) +{ + if (!set->has_any_uses ()) + return; + + auto *use = *set->all_uses ().begin (); + do + { + auto *next_use = use->next_use (); + if (use->is_in_phi ()) + { + // This call will not recurse. + process_uses_of_deleted_def (use->phi ()); + delete_phi (use->phi ()); + } + else + { + gcc_assert (use->is_live_out_use ()); + remove_use (use); + } + use = next_use; + } + while (use); + gcc_assert (!set->has_any_uses ()); +} + // Update the REG_NOTES of INSN, whose pattern has just been changed. static void update_notes (rtx_insn *insn) @@ -695,7 +724,8 @@ function_info::change_insns (array_slice changes) } // Remove all definitions that are no longer needed. After the above, - // such definitions should no longer have any registered users. + // the only uses of such definitions should be dead phis and now-redundant + // live-out uses. // // In particular, this means that consumers must handle debug // instructions before removing a set. @@ -704,7 +734,8 @@ function_info::change_insns (array_slice changes) if (def->m_has_been_superceded) { auto *set = dyn_cast (def); - gcc_assert (!set || !set->has_any_uses ()); + if (set && set->has_any_uses ()) + process_uses_of_deleted_def (set); remove_def (def); } diff --git a/gcc/rtl-ssa/functions.h b/gcc/rtl-ssa/functions.h index 73690a0e63b..cd90b6aa9df 100644 --- a/gcc/rtl-ssa/functions.h +++ b/gcc/rtl-ssa/functions.h @@ -263,6 +263,7 @@ private: bb_info *create_bb_info (basic_block); void append_bb (bb_info *); + void process_uses_of_deleted_def (set_info *); insn_info *add_placeholder_after (insn_info *); void possibly_queue_changes (insn_change &); void finalize_new_accesses (insn_change &, insn_info *);