From patchwork Wed Mar 22 10:01:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 73338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2253384wrt; Wed, 22 Mar 2023 03:02:42 -0700 (PDT) X-Google-Smtp-Source: AK7set88gdJN7g00rCc/nVY3bTUk9g0D1pDab4k/nzebIvzcnUyGyOeNm1PTMWS3l50eavYNL7Gi X-Received: by 2002:a05:6402:7c8:b0:4af:69b8:52af with SMTP id u8-20020a05640207c800b004af69b852afmr5887196edy.24.1679479362209; Wed, 22 Mar 2023 03:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679479362; cv=none; d=google.com; s=arc-20160816; b=ioi5xA23ZGKaLjzdv1+T9cTzF5gFZvSk/6kFwoQNZF5APOs+lrlILVWE037PTecDKz xNi3BHIXmhE15WL/I+bc39rPbFK1LqueW6vdDVuy6NOyzmkrom0pxLVnaegWc8SdDxec dcyye3HB/CiEL5/Xm8QhoO+Ux5bpZjmclb49MHSTS4UTJcdTSs9/J2x8vjcE+pwfsEMS cKNJrpWcACKQ5M27kK0tX7oUSx2HGpOJaa3lncjIGPfqWsAEA+NXFNPmPF/G9zCzCuAg rxpIRbYCpBJymUJoIV6qaPiK2hoK5cXUq0jpd5CUN9Q1tcAcFKBp64KFp2NHlxdkEnV9 eoHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=+dBpAo0szVGGz1LkEVrvmjGhW8gu6ZModURRQRSbwc0=; b=vxCfnFi15B9zxDf7y4DNZmDTsK69cL5n792LSuqzMZXbALtyWXRhzKF2J/PzrVoamY mO704Z0tlEBfi6lbuXtcBgPIEkAhXIxgmzZC8A0aBuna5c87qMytiOMMC1EUu1Sb0RGd Efl9sKPZgl6R82rL2AUyhgGE3d+QS7KJpsja4AoJsdx6ISICvPjC0bqYTRgDmAkgKZNM 7o1lYoDDRSMWLur3azP+J3vR/UbkZ1G2WWQSqJeemsJjhzQDiXDK1tH2Bs8SvPWI4kkN EvRVyAKRQBU0LYhgIDF+R2rhJL1fztN6fSJupOc5CqcW472cZ8etlpEf0hFqRvKifizC b6uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tcN4yIFC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id dy24-20020a05640231f800b004acb4f52ecesi8008510edb.156.2023.03.22.03.02.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 03:02:42 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tcN4yIFC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DDC59385735E for ; Wed, 22 Mar 2023 10:02:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDC59385735E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679479360; bh=+dBpAo0szVGGz1LkEVrvmjGhW8gu6ZModURRQRSbwc0=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tcN4yIFCXtZlK/Kxxw/J3UOEYliRw6FwTz9mOveqJZMmdeJwwzegR0vLO6x1KgbVv DeQVCUz5vA3FGlw/lOkxROtH7IeXLITNaYVDyuJj1EEBGC04dJrBj5TOZNEadUDFG6 PPPPCxw5IK0fpoy27C/YD5hs4W2FETJ08MDSQA9I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 79F293858C1F for ; Wed, 22 Mar 2023 10:01:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79F293858C1F Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6229520C28; Wed, 22 Mar 2023 10:01:54 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 561042C141; Wed, 22 Mar 2023 10:01:54 +0000 (UTC) Date: Wed, 22 Mar 2023 10:01:54 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] rtl-optimization/109237 - quadraticness in delete_trivially_dead_insns User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230322100240.DDC59385735E@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761061751698983197?= X-GMAIL-MSGID: =?utf-8?q?1761061751698983197?= The following addresses quadraticness in processing debug insns in delete_trivially_dead_insns and insn_live_p by using TREE_VISITED on the INSN_VAR_LOCATION_DECL to indicate a later debug bind with the same decl and no intervening real insn or debug marker. That gets rid of the NEXT_INSN walk in insn_live_p in favor of first clearing TREE_VISITED in the first loop over insn and the book-keeping of decls we set the bit since we need to clear them when visiting a real or debug marker insn. That improves the time spent in delete_trivially_dead_insns from 10.6s to 2.2s for the testcase. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK? Thanks, Richard. PR rtl-optimization/109237 * cse.cc (insn_live_p): Remove NEXT_INSN walk, instead check TREE_VISITED on INSN_VAR_LOCATION_DECL. (delete_trivially_dead_insns): Maintain TREE_VISITED on active debug bind INSN_VAR_LOCATION_DECL. --- gcc/cse.cc | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/gcc/cse.cc b/gcc/cse.cc index 8fbda4ecc86..204047b0e0b 100644 --- a/gcc/cse.cc +++ b/gcc/cse.cc @@ -6906,22 +6906,12 @@ insn_live_p (rtx_insn *insn, int *counts) } else if (DEBUG_INSN_P (insn)) { - rtx_insn *next; - if (DEBUG_MARKER_INSN_P (insn)) return true; - for (next = NEXT_INSN (insn); next; next = NEXT_INSN (next)) - if (NOTE_P (next)) - continue; - else if (!DEBUG_INSN_P (next)) - return true; - /* If we find an inspection point, such as a debug begin stmt, - we want to keep the earlier debug insn. */ - else if (DEBUG_MARKER_INSN_P (next)) - return true; - else if (INSN_VAR_LOCATION_DECL (insn) == INSN_VAR_LOCATION_DECL (next)) - return false; + if (DEBUG_BIND_INSN_P (insn) + && TREE_VISITED (INSN_VAR_LOCATION_DECL (insn))) + return false; return true; } @@ -7007,8 +6997,11 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg) counts = XCNEWVEC (int, nreg * 3); for (insn = insns; insn; insn = NEXT_INSN (insn)) if (DEBUG_BIND_INSN_P (insn)) - count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg, - NULL_RTX, 1); + { + count_reg_usage (INSN_VAR_LOCATION_LOC (insn), counts + nreg, + NULL_RTX, 1); + TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 0; + } else if (INSN_P (insn)) { count_reg_usage (insn, counts, NULL_RTX, 1); @@ -7048,6 +7041,7 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg) the setter. Then go through DEBUG_INSNs and if a DEBUG_EXPR has been created for the unused register, replace it with the DEBUG_EXPR, otherwise reset the DEBUG_INSN. */ + auto_vec later_debug_set_vars; for (insn = get_last_insn (); insn; insn = prev) { int live_insn = 0; @@ -7110,6 +7104,21 @@ delete_trivially_dead_insns (rtx_insn *insns, int nreg) } cse_cfg_altered |= delete_insn_and_edges (insn); } + else + { + if (!DEBUG_INSN_P (insn) || DEBUG_MARKER_INSN_P (insn)) + { + for (tree var : later_debug_set_vars) + TREE_VISITED (var) = 0; + later_debug_set_vars.truncate (0); + } + else if (DEBUG_BIND_INSN_P (insn) + && !TREE_VISITED (INSN_VAR_LOCATION_DECL (insn))) + { + later_debug_set_vars.safe_push (INSN_VAR_LOCATION_DECL (insn)); + TREE_VISITED (INSN_VAR_LOCATION_DECL (insn)) = 1; + } + } } if (MAY_HAVE_DEBUG_BIND_INSNS)