From patchwork Tue Oct 24 17:58:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 157653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2112051vqx; Tue, 24 Oct 2023 10:59:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCyuR/iNraovSKks+t0+RQJqZW50aFu9dh2JEROd752SspPvu/JPKDMWDtO1U9PdHBRz75 X-Received: by 2002:a05:622a:1a16:b0:418:f70:df1 with SMTP id f22-20020a05622a1a1600b004180f700df1mr14693017qtb.42.1698170340659; Tue, 24 Oct 2023 10:59:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698170340; cv=pass; d=google.com; s=arc-20160816; b=ua5+6yc48xv1QW305+8qq+Zw2KqjRRYzAZpj9R2BLLj2X9L9VAWDhDLfQPZtBDvRH7 7S9udQPL3kWmZ6EvSKjrZlXETPut2eR1rqRHexydNLHPf8A0SBrRMVzVtNtN7Ew0Yz9S 1uhW+fGBgu8Frkyo8fKKqMH8AQ9mU1+Tu3zeBWf/b9gfNZFQB2uDX8ib6hWlWkTX7M6w KiEd8wQiSY24CZvzu74/aUywgXChykzFSDZxhCOPv/d07zbNvI8x7imy7E0aF/TU3ZLR OumshrdpsGQ1ecR/dAatfS95FrQ/9uVM3TCJxv52PoTMJalALm0Z0m6BLBk7rIb3x27T 1IGA== 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=GY8Y+5II9vLrxqQSZ18mqPzGfn1ry6LGIA+M0r0qPs4=; fh=WSfZ840Wi6BqtTz8VZjapJ1yCCJ9QRCfxSVxwOS9rLc=; b=GEsW4eEcP9nXef5oWDIIeuCAOK303OMPIfXIJ5byhasfRpbBQHdMw6aQvyPlQzxp7B ok1sE63EAm7N64A3e7UP7H6GnHpV7v/38qrbhNii46EB9xUDSCFhkBahlIPlxB7pCHf/ ZeOv6BefpIu/pKSR4ugkxhICoEglN8Jm2khlP/fjfA9UgdUvI2h28+oFPLOT+jPtvUMy 6Ds+7v3KKTsRgs1F37De0UuJBt0Otl6xmBDRBFqU9Bc/qwg0SBBM/QOUn+Jn3inxb1we 56HFnMuKgRe50lhlAoQmGFT7OWgNB06a9uluHwaDml0vLbrY+MfPdgl2CSckqPA09ASw kJDQ== 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 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id n15-20020a05622a040f00b00419930eb097si7703690qtx.215.2023.10.24.10.59.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:59:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; 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 8.43.85.97 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 E92FD385F015 for ; Tue, 24 Oct 2023 17:58:48 +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 43C5D3858CDB for ; Tue, 24 Oct 2023 17:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43C5D3858CDB 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 43C5D3858CDB 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=1698170304; cv=none; b=O1Ia2Jk2sEeQNlnSCmwA/i7LOoDD5wI/fJEFy89WAUOcV864xMMZHTv88QvvfSkFSn4dL6HknFc+eBuLY5F1k1JX7baBzLWTeg3ZjvgniseZ5uXe7L8eLxY1ohtqn3TX/L1ZiE3gyHU31g9S4YVt/zUVY/Wto7t1H4KJgcd1dfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698170304; c=relaxed/simple; bh=DMObM9pB/ZwIzZRoa2+OAGN/UxM0pXwKzG1QLyXzhbw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=fkqNbjUEHNbpE1Q+Q9V+mF91UDKfZ/JLco5FWE0lcGRBVkrD5IHU/kCFKKB2MvMYwdkoJImoljNg5onmAlSjlC0quabjEaYFSBM5hwDHBo3DcEIWWYXHUpKtVzOZE8FmA4rJiJimXBc/wW8kCChOY+MzW/n77G9/5wXZKoFHPUg= 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 0D6C62F4; Tue, 24 Oct 2023 10:59:04 -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 5112B3F64C; Tue, 24 Oct 2023 10:58:22 -0700 (PDT) From: Richard Sandiford To: jlaw@ventanamicro.com, gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 1/3] rtl-ssa: Use frequency-weighted insn costs Date: Tue, 24 Oct 2023 18:58:03 +0100 Message-Id: <20231024175805.3359331-2-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231024175805.3359331-1-richard.sandiford@arm.com> References: <20231024175805.3359331-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: 1780660663289485010 X-GMAIL-MSGID: 1780660663289485010 rtl_ssa::changes_are_worthwhile used the standard approach of summing up the individual costs of the old and new sequences to see which one is better overall. But when optimising for speed and changing instructions in multiple blocks, it seems better to weight the cost of each instruction by its execution frequency. (We already do something similar for SLP layouts.) gcc/ * rtl-ssa/changes.cc: Include sreal.h. (rtl_ssa::changes_are_worthwhile): When optimizing for speed, scale the cost of each instruction by its execution frequency. --- gcc/rtl-ssa/changes.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gcc/rtl-ssa/changes.cc b/gcc/rtl-ssa/changes.cc index 3e14069421c..aab532b9f26 100644 --- a/gcc/rtl-ssa/changes.cc +++ b/gcc/rtl-ssa/changes.cc @@ -34,6 +34,7 @@ #include "emit-rtl.h" #include "cfghooks.h" #include "cfgrtl.h" +#include "sreal.h" using namespace rtl_ssa; @@ -171,18 +172,33 @@ rtl_ssa::changes_are_worthwhile (array_slice changes, { unsigned int old_cost = 0; unsigned int new_cost = 0; + sreal weighted_old_cost = 0; + sreal weighted_new_cost = 0; + auto entry_count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; for (insn_change *change : changes) { old_cost += change->old_cost (); + basic_block cfg_bb = change->bb ()->cfg_bb (); + bool for_speed = optimize_bb_for_speed_p (cfg_bb); + if (for_speed) + weighted_old_cost += (cfg_bb->count.to_sreal_scale (entry_count) + * change->old_cost ()); if (!change->is_deletion ()) { - basic_block cfg_bb = change->bb ()->cfg_bb (); - change->new_cost = insn_cost (change->rtl (), - optimize_bb_for_speed_p (cfg_bb)); + change->new_cost = insn_cost (change->rtl (), for_speed); new_cost += change->new_cost; + if (for_speed) + weighted_new_cost += (cfg_bb->count.to_sreal_scale (entry_count) + * change->new_cost); } } - bool ok_p = (strict_p ? new_cost < old_cost : new_cost <= old_cost); + bool ok_p; + if (weighted_new_cost != weighted_old_cost) + ok_p = weighted_new_cost < weighted_old_cost; + else if (strict_p) + ok_p = new_cost < old_cost; + else + ok_p = new_cost <= old_cost; if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "original cost"); @@ -192,6 +208,8 @@ rtl_ssa::changes_are_worthwhile (array_slice changes, fprintf (dump_file, " %c %d", sep, change->old_cost ()); sep = '+'; } + if (weighted_old_cost != 0) + fprintf (dump_file, " (weighted: %f)", weighted_old_cost.to_double ()); fprintf (dump_file, ", replacement cost"); sep = '='; for (const insn_change *change : changes) @@ -200,6 +218,8 @@ rtl_ssa::changes_are_worthwhile (array_slice changes, fprintf (dump_file, " %c %d", sep, change->new_cost); sep = '+'; } + if (weighted_new_cost != 0) + fprintf (dump_file, " (weighted: %f)", weighted_new_cost.to_double ()); fprintf (dump_file, "; %s\n", ok_p ? "keeping replacement" : "rejecting replacement"); } From patchwork Tue Oct 24 17:58: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: 157654 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2112092vqx; Tue, 24 Oct 2023 10:59:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGE0CNQ38nXASo368VTLhnsH5y9k9YYuTYJBn9bMhIhCY+0RNeWcA25Rr6u1VM1i1CA6lDt X-Received: by 2002:a67:c092:0:b0:452:55f5:55e9 with SMTP id x18-20020a67c092000000b0045255f555e9mr13472157vsi.14.1698170345946; Tue, 24 Oct 2023 10:59:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698170345; cv=pass; d=google.com; s=arc-20160816; b=gr3Xxr+mSwkcRXB00/wAxUg3ZDk/E5sS+qxvM5BaWGWYutFMUrNuwtnn443LgIKV7+ Pb+VoTZwQWmzv48CtDCe+5MJPAbU2w368FU7yOdSr3kc6eQ8ExYeW+C3TS1IR6yreXxv ijpR9WxUirlDJ/GXBcfF/A4rT7n9R8Oh0X0hBxx/9nM/NXbb1UPSQRSyspK7ZW1XGZNT pfmcZDMAEsl0UlmnZTpCaIczZAg2G3ipn/FccWh7iKyOueCPO1VXejjKfuQSrpMU111Y QETKyLJ1PRi/xoC3bmrX1kiLi1arbTTCVvlIIBra4h7VVWvhRcnPYuH1sqotuSsFoxeg ns3A== 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=DWMDAz2yBO7KQtzKNJWYAfmgJPWxSCimiCKRylOW7LE=; fh=WSfZ840Wi6BqtTz8VZjapJ1yCCJ9QRCfxSVxwOS9rLc=; b=R0OlFqmOTH3gY3hKNd4ggsoABHLNiDuLcUbR1mHwLDOYUqCeGSbaCPj3ZTBCHQ8PgG 48vb7jy6crNquiTQ2QO5ysR+6y/teQWHUFTdr7lPE4ipZjnwsPN2iCFi06IFnRScFwS8 pSRM5drZLiUCC9q7UGJMMAQcukgFekh/zZ1uyarul3BDBzsFavI0ekyhlKVYDzln+a4b N1HBPHte1+9A55/f6IugFxOi8g2ihuu2LFgEzxKysBiBScPfvlX/sELJMieXxhDDvope 3dTzoGhBzQitDNz1ginoCoRZXg/5BKYBVJxNkWMYUeROmxGrT+qgavG/YPiXmFX+6SPK AmjQ== 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 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id l9-20020a0cd6c9000000b0065afc346b27si7147653qvi.28.2023.10.24.10.59.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; 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 8.43.85.97 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 6A5F3385DC15 for ; Tue, 24 Oct 2023 17:58:53 +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 BEABA3858421 for ; Tue, 24 Oct 2023 17:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEABA3858421 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 BEABA3858421 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=1698170310; cv=none; b=DexueRPIBjDXIZxncM2WpuwX3DDqjJ2qzXoNM3/1cjILI53C7wuDfFTn/h5bsZSJ9PP0PTpgZqsSoPuQFQnTyKlCPY4oau6splyuDFmxBDOInTFLq0VUWa3A/hVcn0F6EtUDzJ1U3oryVKKQY7YAIyZE4YV/i+SallyGSpVd4RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698170310; c=relaxed/simple; bh=TSpvnq/8AZb0DhMI2CFQg1Wa5X+PPdA2XbyHnWyFQoA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=QdAKXrh6rFLSxBMsf83XThrFoPlm+fSNvfrlcPZxT18DiMR68nqwrsf6XUfERfnX+skBrMOZS1OKU8rx9biZvC7KUNhOh3CiaerA7X9TegloBnK+LrWCHpXuBhjgrMg7a/VXiuB05pVIcQD5EMBDo9Bg836SWrfUpNtBSMpBsds= 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 9CA192F4; Tue, 24 Oct 2023 10:59:09 -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 DF8003F64C; Tue, 24 Oct 2023 10:58:27 -0700 (PDT) From: Richard Sandiford To: jlaw@ventanamicro.com, gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 2/3] rtl-ssa: Extend make_uses_available Date: Tue, 24 Oct 2023 18:58:04 +0100 Message-Id: <20231024175805.3359331-3-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231024175805.3359331-1-richard.sandiford@arm.com> References: <20231024175805.3359331-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: 1780660668682898853 X-GMAIL-MSGID: 1780660668682898853 The first in-tree use of RTL-SSA was fwprop, and one of the goals was to make the fwprop rewrite preserve the old behaviour as far as possible. The switch to RTL-SSA was supposed to be a pure infrastructure change. So RTL-SSA has various FIXMEs for things that were artifically limited to faciliate the old-fwprop vs. new-fwprop comparison. One of the things that fwprop wants to do is extend live ranges, and function_info::make_use_available tried to keep within the cases that old fwprop could handle. Since the information is built in extended basic blocks, it's easy to handle intra-EBB queries directly. This patch does that, and removes the associated FIXME. To get a flavour for how much difference this makes, I tried compiling the testsuite at -Os for at least one target per supported CPU and OS. For most targets, only a handful of tests changed, but the vast majority of changes were positive. The only target that seemed to benefit significantly was i686-apple-darwin. The main point of the patch is to remove the FIXME and to enable the upcoming post-RA late-combine pass to handle more cases. gcc/ * rtl-ssa/functions.h (function_info::remains_available_at_insn): New member function. * rtl-ssa/accesses.cc (function_info::remains_available_at_insn): Likewise. (function_info::make_use_available): Avoid false negatives for queries within an EBB. --- gcc/rtl-ssa/accesses.cc | 37 +++++++++++++++++++++++++++++++++++-- gcc/rtl-ssa/functions.h | 4 ++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/rtl-ssa/accesses.cc b/gcc/rtl-ssa/accesses.cc index c35c7efb73d..1b25ecc3e23 100644 --- a/gcc/rtl-ssa/accesses.cc +++ b/gcc/rtl-ssa/accesses.cc @@ -1303,6 +1303,33 @@ function_info::insert_temp_clobber (obstack_watermark &watermark, return insert_access (watermark, clobber, old_defs); } +// See the comment above the declaration. +bool +function_info::remains_available_at_insn (const set_info *set, + insn_info *insn) +{ + auto *ebb = set->ebb (); + gcc_checking_assert (ebb == insn->ebb ()); + + def_info *next_def = set->next_def (); + if (next_def && *next_def->insn () < *insn) + return false; + + if (HARD_REGISTER_NUM_P (set->regno ()) + && TEST_HARD_REG_BIT (m_clobbered_by_calls, set->regno ())) + for (ebb_call_clobbers_info *call_group : ebb->call_clobbers ()) + { + if (!call_group->clobbers (set->resource ())) + continue; + + insn_info *call_insn = next_call_clobbers (*call_group, insn); + if (call_insn && *call_insn < *insn) + return false; + } + + return true; +} + // See the comment above the declaration. bool function_info::remains_available_on_exit (const set_info *set, bb_info *bb) @@ -1354,14 +1381,20 @@ function_info::make_use_available (use_info *use, bb_info *bb, if (is_single_dominating_def (def)) return use; - // FIXME: Deliberately limited for fwprop compatibility testing. + if (def->ebb () == bb->ebb ()) + { + if (remains_available_at_insn (def, bb->head_insn ())) + return use; + return nullptr; + } + basic_block cfg_bb = bb->cfg_bb (); bb_info *use_bb = use->bb (); if (single_pred_p (cfg_bb) && single_pred (cfg_bb) == use_bb->cfg_bb () && remains_available_on_exit (def, use_bb)) { - if (def->ebb () == bb->ebb () || will_be_debug_use) + if (will_be_debug_use) return use; resource_info resource = use->resource (); diff --git a/gcc/rtl-ssa/functions.h b/gcc/rtl-ssa/functions.h index ab253e750cb..ecb40fdaf57 100644 --- a/gcc/rtl-ssa/functions.h +++ b/gcc/rtl-ssa/functions.h @@ -121,6 +121,10 @@ public: // scope until the change has been aborted or successfully completed. obstack_watermark new_change_attempt () { return &m_temp_obstack; } + // SET and INSN belong to the same EBB, with SET occuring before INSN. + // Return true if SET is still available at INSN. + bool remains_available_at_insn (const set_info *set, insn_info *insn); + // SET either occurs in BB or is known to be available on entry to BB. // Return true if it is also available on exit from BB. (The value // might or might not be live.) From patchwork Tue Oct 24 17:58:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 157655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2112201vqx; Tue, 24 Oct 2023 10:59:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJh3Yi+++3RZpYl6dcNeZlM6m9HV/Y5669cbLQkmf/B4XU2PWkFYMNd6ndBCCsz+v4K1Fn X-Received: by 2002:ac8:5801:0:b0:418:1ba6:2b37 with SMTP id g1-20020ac85801000000b004181ba62b37mr12434573qtg.63.1698170361290; Tue, 24 Oct 2023 10:59:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698170361; cv=pass; d=google.com; s=arc-20160816; b=CDPedSYq+6myUfK2BSatygPCNw4/Z35LIwJMset7qVHYU26fphxz6QLSvNXp8U9Gs+ 2Cl8LpOlWmWcfkyfjgUaj4VVX/voi4bMh5xKpaQlZMTPHKSh6/H3/Z1I5y+rE2C4SbJC 2Lg35Q3z3RWZm/7ASQzqohznl3U6DInN86D4/5HlEGkTtU5XiVy2q43iB9CaOCOjL4d2 tW7t/XUnchZvuvXHImldhD9suub2gpCKM87nAf5KtoYpBSq3tNTnFefl/XmiSiYifllc bGt9GV671uDLdFxVXd/DbRgZHVOYm7ieXalxSpJpaxQlc9EEDSE2iTchNrArFRG6zKf9 W9JA== 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=NHIMV7i1gKmPTEHf9qiN6MIBNw8aTcgZ9cHA3xUqQKE=; fh=WSfZ840Wi6BqtTz8VZjapJ1yCCJ9QRCfxSVxwOS9rLc=; b=vJs9/ArGbx1sc0pdGjmleZpUl69v3xaz1LqA5I6LjnNTHqdd/BbtZfo0aR3o0XXnfh +2s/jVNAgqeuDiLb1cqIjl2EzGu9X2MLtlAp04Jor/j4ey2A0GsXcFv6OIvSgUN7c7Qq lGTzN5/83VH39paBUKANBydC499Sd4MVFwwQ6HIF+zi9zQyuFIQkuC7qEByyzfht1/Ep 02xG4e9LOfQiK+Z6Pkyv70UQvd6epZXFHgQmrFzg6E3FFP3fiNnB84EwnqkVE4fjwB51 +JMsZ+COkcjfdC/2HQGALNQJandvXhHwjWPXt9SziKEIghpQGvLpiqgzMX8wud0dxaa5 0vVA== 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 l13-20020a05622a050d00b0041cbed097e4si7370039qtx.227.2023.10.24.10.59.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 10:59:21 -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 2679A3858005 for ; Tue, 24 Oct 2023 17:59:15 +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 55CDF3857730 for ; Tue, 24 Oct 2023 17:58:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55CDF3857730 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 55CDF3857730 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=1698170316; cv=none; b=K+eCCDgyltHMXA4Cbr0PKZT/wORqk4G0kNyZHWfZ3tp0eCp8jbFOAkh5Ab6U4l+6GJ+J8LCpVG8uQdxMtdVDBgeyMAQh2jqckyJNKuzHahDf15SsL67r+YlWiU2sgGz06ptVQQgeQFSqYOScyOJdXAUmGWwJ+mIZXNPk0niwWME= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698170316; c=relaxed/simple; bh=ieOqWF7LKxxkCgUXO/i78DSUb+rcUioQpJIW5epaAcM=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=VH7mpK5ivlZB31E1kWCAkpYKpLSFQ7Zr7QtjUeFvqHHgYt25TrLZMpebG0juJykM8pfcLH73kt0A7E+g2S3hXHv+aW0CNWa57neQTKrqS8Qulrw5qY92qC+9XXFMAGRHWDYR7F8d/Mm9aiy18L+Xwi95JpbmSvjv5cKC3cvqBWQ= 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 37D502F4; Tue, 24 Oct 2023 10:59:15 -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 7B2E73F64C; Tue, 24 Oct 2023 10:58:33 -0700 (PDT) From: Richard Sandiford To: jlaw@ventanamicro.com, gcc-patches@gcc.gnu.org Cc: Richard Sandiford Subject: [PATCH 3/3] rtl-ssa: Add new helper functions Date: Tue, 24 Oct 2023 18:58:05 +0100 Message-Id: <20231024175805.3359331-4-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231024175805.3359331-1-richard.sandiford@arm.com> References: <20231024175805.3359331-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, KAM_SHORT, 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: 1780660684725106844 X-GMAIL-MSGID: 1780660684725106844 This patch adds some RTL-SSA helper functions. They will be used by the upcoming late-combine pass. The patch contains the first non-template out-of-line function declared in movement.h, so it adds a movement.cc. I realise it seems a bit over-the-top to have a file with just one function, but it might grow in future. :) gcc/ * Makefile.in (OBJS): Add rtl-ssa/movement.o. * rtl-ssa/access-utils.h (accesses_include_nonfixed_hard_registers) (single_set_info): New functions. (remove_uses_of_def, accesses_reference_same_resource): Declare. (insn_clobbers_resources): Likewise. * rtl-ssa/accesses.cc (rtl_ssa::remove_uses_of_def): New function. (rtl_ssa::accesses_reference_same_resource): Likewise. (rtl_ssa::insn_clobbers_resources): Likewise. * rtl-ssa/movement.h (can_move_insn_p): Declare. * rtl-ssa/movement.cc: New file. --- gcc/Makefile.in | 1 + gcc/rtl-ssa/access-utils.h | 41 +++++++++++++++++++++++++ gcc/rtl-ssa/accesses.cc | 63 ++++++++++++++++++++++++++++++++++++++ gcc/rtl-ssa/movement.cc | 40 ++++++++++++++++++++++++ gcc/rtl-ssa/movement.h | 4 +++ 5 files changed, 149 insertions(+) create mode 100644 gcc/rtl-ssa/movement.cc diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 7b7a4ff789a..91d6bfbea4d 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1635,6 +1635,7 @@ OBJS = \ rtl-ssa/changes.o \ rtl-ssa/functions.o \ rtl-ssa/insns.o \ + rtl-ssa/movement.o \ rtl-tests.o \ rtl.o \ rtlhash.o \ diff --git a/gcc/rtl-ssa/access-utils.h b/gcc/rtl-ssa/access-utils.h index 0d7a57f843c..f078625babf 100644 --- a/gcc/rtl-ssa/access-utils.h +++ b/gcc/rtl-ssa/access-utils.h @@ -33,6 +33,20 @@ accesses_include_hard_registers (const access_array &accesses) return accesses.size () && HARD_REGISTER_NUM_P (accesses.front ()->regno ()); } +// Return true if ACCESSES includes a reference to a non-fixed hard register. +inline bool +accesses_include_nonfixed_hard_registers (access_array accesses) +{ + for (access_info *access : accesses) + { + if (!HARD_REGISTER_NUM_P (access->regno ())) + break; + if (!fixed_regs[access->regno ()]) + return true; + } + return false; +} + // Return true if sorted array ACCESSES includes an access to memory. inline bool accesses_include_memory (const access_array &accesses) @@ -246,6 +260,22 @@ last_def (def_mux mux) return mux.last_def (); } +// If INSN's definitions contain a single set, return that set, otherwise +// return null. +inline set_info * +single_set_info (insn_info *insn) +{ + set_info *set = nullptr; + for (auto def : insn->defs ()) + if (auto this_set = dyn_cast (def)) + { + if (set) + return nullptr; + set = this_set; + } + return set; +} + int lookup_use (splay_tree &, insn_info *); int lookup_def (def_splay_tree &, insn_info *); int lookup_clobber (clobber_tree &, insn_info *); @@ -539,6 +569,10 @@ insert_access (obstack_watermark &watermark, return T (insert_access_base (watermark, access1, accesses2)); } +// Return a copy of USES that drops any use of DEF. +use_array remove_uses_of_def (obstack_watermark &, use_array uses, + def_info *def); + // The underlying non-template implementation of remove_note_accesses. access_array remove_note_accesses_base (obstack_watermark &, access_array); @@ -554,4 +588,11 @@ remove_note_accesses (obstack_watermark &watermark, T accesses) return T (remove_note_accesses_base (watermark, accesses)); } +// Return true if ACCESSES1 and ACCESSES2 have at least one resource in common. +bool accesses_reference_same_resource (access_array accesses1, + access_array accesses2); + +// Return true if INSN clobbers the value of any resources in ACCESSES. +bool insn_clobbers_resources (insn_info *insn, access_array accesses); + } diff --git a/gcc/rtl-ssa/accesses.cc b/gcc/rtl-ssa/accesses.cc index 1b25ecc3e23..510545a8bad 100644 --- a/gcc/rtl-ssa/accesses.cc +++ b/gcc/rtl-ssa/accesses.cc @@ -1569,6 +1569,19 @@ rtl_ssa::insert_access_base (obstack_watermark &watermark, return builder.finish (); } +// See the comment above the declaration. +use_array +rtl_ssa::remove_uses_of_def (obstack_watermark &watermark, use_array uses, + def_info *def) +{ + access_array_builder uses_builder (watermark); + uses_builder.reserve (uses.size ()); + for (use_info *use : uses) + if (use->def () != def) + uses_builder.quick_push (use); + return use_array (uses_builder.finish ()); +} + // See the comment above the declaration. access_array rtl_ssa::remove_note_accesses_base (obstack_watermark &watermark, @@ -1587,6 +1600,56 @@ rtl_ssa::remove_note_accesses_base (obstack_watermark &watermark, return accesses; } +// See the comment above the declaration. +bool +rtl_ssa::accesses_reference_same_resource (access_array accesses1, + access_array accesses2) +{ + auto i1 = accesses1.begin (); + auto end1 = accesses1.end (); + auto i2 = accesses2.begin (); + auto end2 = accesses2.end (); + + while (i1 != end1 && i2 != end2) + { + access_info *access1 = *i1; + access_info *access2 = *i2; + + unsigned int regno1 = access1->regno (); + unsigned int regno2 = access2->regno (); + if (regno1 == regno2) + return true; + + if (regno1 < regno2) + ++i1; + else + ++i2; + } + return false; +} + +// See the comment above the declaration. +bool +rtl_ssa::insn_clobbers_resources (insn_info *insn, access_array accesses) +{ + if (accesses_reference_same_resource (insn->defs (), accesses)) + return true; + + if (insn->is_call () && accesses_include_hard_registers (accesses)) + { + function_abi abi = insn_callee_abi (insn->rtl ()); + for (const access_info *access : accesses) + { + if (!HARD_REGISTER_NUM_P (access->regno ())) + break; + if (abi.clobbers_reg_p (access->mode (), access->regno ())) + return true; + } + } + + return false; +} + // Print RESOURCE to PP. void rtl_ssa::pp_resource (pretty_printer *pp, resource_info resource) diff --git a/gcc/rtl-ssa/movement.cc b/gcc/rtl-ssa/movement.cc new file mode 100644 index 00000000000..fcf5f8bc822 --- /dev/null +++ b/gcc/rtl-ssa/movement.cc @@ -0,0 +1,40 @@ +// RTL SSA routines for moving instructions +// Copyright (C) 2023 Free Software Foundation, Inc. +// +// This file is part of GCC. +// +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. +// +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#define INCLUDE_ALGORITHM +#define INCLUDE_FUNCTIONAL +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "backend.h" +#include "rtl.h" +#include "df.h" +#include "rtl-ssa.h" +#include "rtl-ssa/internals.h" +#include "rtl-ssa/internals.inl" + +using namespace rtl_ssa; + +// See the comment above the declaration. +bool +rtl_ssa::can_move_insn_p (insn_info *insn) +{ + return (!control_flow_insn_p (insn->rtl ()) + && !may_trap_p (PATTERN (insn->rtl ()))); +} diff --git a/gcc/rtl-ssa/movement.h b/gcc/rtl-ssa/movement.h index 67370947dbd..ec076db406f 100644 --- a/gcc/rtl-ssa/movement.h +++ b/gcc/rtl-ssa/movement.h @@ -19,6 +19,10 @@ namespace rtl_ssa { +// Return true if INSN can in principle be moved around, and if RTL-SSA +// has enough information to do that. +bool can_move_insn_p (insn_info *); + // Restrict movement range RANGE so that the instruction is placed later // than INSN. (The movement range is the range of instructions after which // an instruction can be placed.)