From patchwork Fri Feb 3 13:05:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 64248 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C31D3858428 for ; Fri, 3 Feb 2023 13:06:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C31D3858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675429572; bh=M3cNlUd8wk0c5FWWBESrNniMtGb0zEsA1FJ+KddT+P0=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UaILA1jWKTzBOkJ9ejloZff3UPQsjWHusRj91O6tyv1vGXJzKPtHSadRwtbSe6wbV I8ACqP2lIWMDxIN8uXoV3iEVOPJ4dgSaHwpJyAQuYF2UX2VAZjvZpmNd+Zp5prolqW ak6rwtqPA/P7EkggyLza+WpTkD3iQaQJtfg2DUR8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 10C9B3858D20 for ; Fri, 3 Feb 2023 13:05:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10C9B3858D20 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2A63434730; Fri, 3 Feb 2023 13:05:39 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 12F0A1346D; Fri, 3 Feb 2023 13:05:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 4UF9A6MG3WNceAAAMHmgww (envelope-from ); Fri, 03 Feb 2023 13:05:39 +0000 Date: Fri, 3 Feb 2023 14:05:38 +0100 (CET) To: gcc-patches@gcc.gnu.org cc: jeffreyalaw@gmail.com Subject: [PATCH] Speedup cse_insn MIME-Version: 1.0 Message-Id: <20230203130539.12F0A1346D@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When cse_insn prunes src{,_folded,_eqv_here,_related} with the equivalence set in the *_same_value chain it also searches for an equivalence to the destination of the instruction with /* This is the same as the destination of the insns, we want to prefer it. Copy it to src_related. The code below will then give it a negative cost. */ if (GET_CODE (dest) == code && rtx_equal_p (p->exp, dest)) src_related = p->exp; this picks up the last such equivalence and in particular any later duplicate will be pruned by the preceeding else if (src_related && GET_CODE (src_related) == code && rtx_equal_p (src_related, p->exp)) src_related = 0; first. This wastes cycles doing extra rtx_equal_p checks. The following instead searches for the first destination equivalence separately in this loop and delays using src_related for it until we are about to process that, avoiding another redundant rtx_equal_p check. I've came here because of a testcase with very large equivalence lists and compile-time of cse_insn. The patch below doesn't speed it up significantly since there's no equivalence on the destination. In theory this opens the possibility to track dest_related separately, avoiding the implicit pruning of any previous value in src_related. As is the change should be a no-op for code generation. Bootstrapped and tested on x86_64-unknown-linux-gnu, queued for stage1. * cse.cc (cse_insn): Track an equivalence to the destination separately and delay using src_related for it. --- gcc/cse.cc | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/gcc/cse.cc b/gcc/cse.cc index 8fbda4ecc86..543cb1fe36f 100644 --- a/gcc/cse.cc +++ b/gcc/cse.cc @@ -4614,6 +4614,7 @@ cse_insn (rtx_insn *insn) rtx src_eqv_here; rtx src_const = 0; rtx src_related = 0; + rtx dest_related = 0; bool src_related_is_const_anchor = false; struct table_elt *src_const_elt = 0; int src_cost = MAX_COST; @@ -5085,10 +5086,11 @@ cse_insn (rtx_insn *insn) src_related = 0; /* This is the same as the destination of the insns, we want - to prefer it. Copy it to src_related. The code below will - then give it a negative cost. */ - if (GET_CODE (dest) == code && rtx_equal_p (p->exp, dest)) - src_related = p->exp; + to prefer it. The code below will then give it a negative + cost. */ + if (!dest_related + && GET_CODE (dest) == code && rtx_equal_p (p->exp, dest)) + dest_related = p->exp; } /* Find the cheapest valid equivalent, trying all the available @@ -5130,27 +5132,28 @@ cse_insn (rtx_insn *insn) } } - if (src_related) + if (dest_related) { - if (rtx_equal_p (src_related, dest)) - src_related_cost = src_related_regcost = -1; - else - { - src_related_cost = COST (src_related, mode); - src_related_regcost = approx_reg_cost (src_related); - - /* If a const-anchor is used to synthesize a constant that - normally requires multiple instructions then slightly prefer - it over the original sequence. These instructions are likely - to become redundant now. We can't compare against the cost - of src_eqv_here because, on MIPS for example, multi-insn - constants have zero cost; they are assumed to be hoisted from - loops. */ - if (src_related_is_const_anchor - && src_related_cost == src_cost - && src_eqv_here) - src_related_cost--; - } + src_related_cost = src_related_regcost = -1; + /* Handle it as src_related. */ + src_related = dest_related; + } + else if (src_related) + { + src_related_cost = COST (src_related, mode); + src_related_regcost = approx_reg_cost (src_related); + + /* If a const-anchor is used to synthesize a constant that + normally requires multiple instructions then slightly prefer + it over the original sequence. These instructions are likely + to become redundant now. We can't compare against the cost + of src_eqv_here because, on MIPS for example, multi-insn + constants have zero cost; they are assumed to be hoisted from + loops. */ + if (src_related_is_const_anchor + && src_related_cost == src_cost + && src_eqv_here) + src_related_cost--; } /* If this was an indirect jump insn, a known label will really be