From patchwork Mon May 23 18:34:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 54308 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 3F0FE3857413 for ; Mon, 23 May 2022 18:34:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F0FE3857413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653330897; bh=sFSdXej/sZl6tb9X3Z5IqQe1+LfvpP4WRbrOG1bYRUU=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RAck68QvR3xwFQBboLiJcPcUrXFzoGam1JlZoDGS0qNp8M0qtaQY7BzOTpz+BWy4S IuCuF9vKrSWKXqAK54kGsosNmFuf+SYWczJb+Udp5ErQuMUluPs+A4IKryrfc6GiDo ZNafO7mHKrTJUunr5dRYBGG8MStjINtjcbSaxPnk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id D56863858D32 for ; Mon, 23 May 2022 18:34:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D56863858D32 Received: by mail-pl1-x629.google.com with SMTP id d22so13847430plr.9 for ; Mon, 23 May 2022 11:34:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sFSdXej/sZl6tb9X3Z5IqQe1+LfvpP4WRbrOG1bYRUU=; b=RHPJy3Mmjf9ZO5avr/rGqarz6nav9e6knOLMo8KDezWpkBoLdFwAakUkljwEjbZEZa DG7qllTHA1vy57UO14ElxQiPwkideuewV4hmUAofp8MK19+i1J7sGuHSCPWyl/FboUT/ h73f12orWpuudtiUD8a5cPhyiBc5flmWGMsQzbvSJ4uMvXk1UJtS2iJ0qRawvpQlWEAg 1C5yl266cf17akaW6z4yq4Ub5SaLmSNklaI9it6z6TB5iA4B1WtIWJHOUnYKqSI+qT12 sAok7MJM7VrraxVL4n64xVlXQUk1pDUevbgnzEQzBgW9KpS/+R1E+/9Sh1W7S350oj0C bznQ== X-Gm-Message-State: AOAM531qbmoebb+OoQV6S44UJlZk/aW7GH3QZ3zQOfJM/sYwp90wJd8s QxOhLt4L0NmSWS/voPJXR8d65t9kj+Q= X-Google-Smtp-Source: ABdhPJwIXIIaHgajlS7hjV9N5ZcpXS5zutXNndKhXC5y2EHfRkwOsU9eCxplpQIYoBsfb24FMfDe3A== X-Received: by 2002:a17:902:6b41:b0:15f:2c60:2459 with SMTP id g1-20020a1709026b4100b0015f2c602459mr24111931plt.41.1653330866645; Mon, 23 May 2022 11:34:26 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.88.122]) by smtp.gmail.com with ESMTPSA id s1-20020a170902ea0100b0015e8d4eb1c1sm5394691plg.11.2022.05.23.11.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 11:34:26 -0700 (PDT) Received: by gnu-tgl-3.localdomain (Postfix, from userid 1000) id 7EC0DC0414; Mon, 23 May 2022 11:34:24 -0700 (PDT) Date: Mon, 23 May 2022 11:34:24 -0700 To: Richard Biener Subject: [PATCH v2] DSE: Use the constant store source if possible Message-ID: References: <20220521030120.1977551-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3028.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: GCC Patches Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" On Mon, May 23, 2022 at 12:38:06PM +0200, Richard Biener wrote: > On Sat, May 21, 2022 at 5:02 AM H.J. Lu via Gcc-patches > wrote: > > > > When recording store for RTL dead store elimination, check if the source > > register is set only once to a constant. If yes, record the constant > > as the store source. It eliminates unrolled zero stores after memset 0 > > in a loop where a vector register is used as the zero store source. > > > > gcc/ > > > > PR rtl-optimization/105638 > > * dse.cc (record_store): Use the constant source if the source > > register is set only once. > > > > gcc/testsuite/ > > > > PR rtl-optimization/105638 > > * g++.target/i386/pr105638.C: New test. > > --- > > gcc/dse.cc | 19 ++++++++++ > > gcc/testsuite/g++.target/i386/pr105638.C | 44 ++++++++++++++++++++++++ > > 2 files changed, 63 insertions(+) > > create mode 100644 gcc/testsuite/g++.target/i386/pr105638.C > > > > diff --git a/gcc/dse.cc b/gcc/dse.cc > > index 30c11cee034..0433dd3d846 100644 > > --- a/gcc/dse.cc > > +++ b/gcc/dse.cc > > @@ -1508,6 +1508,25 @@ record_store (rtx body, bb_info_t bb_info) > > > > if (tem && CONSTANT_P (tem)) > > const_rhs = tem; > > + else > > + { > > + /* If RHS is set only once to a constant, set CONST_RHS > > + to the constant. */ > > + df_ref def = DF_REG_DEF_CHAIN (REGNO (rhs)); > > + if (def != nullptr > > + && !DF_REF_IS_ARTIFICIAL (def) > > + && !DF_REF_NEXT_REG (def)) > > + { > > + rtx_insn *def_insn = DF_REF_INSN (def); > > + rtx def_body = PATTERN (def_insn); > > + if (GET_CODE (def_body) == SET) > > + { > > + rtx def_src = SET_SRC (def_body); > > + if (CONSTANT_P (def_src)) > > + const_rhs = def_src; > > doesn't DSE have its own tracking of stored values? Shouldn't we It tracks stored values only within the basic block. When RTL loop invariant motion hoists a constant initialization out of the loop into a separate basic block, the constant store value becomes unknown within the original basic block. > improve _that_ if it is not enough? I also wonder if you need to My patch extends DSE stored value tracking to include the constant which is set only once in another basic block. > verify the SET isn't partial? > Here is the v2 patch to check that the constant is set by a non-partial unconditional load. OK for master? Thanks. H.J. --- RTL DSE tracks redundant constant stores within a basic block. When RTL loop invariant motion hoists a constant initialization out of the loop into a separate basic block, the constant store value becomes unknown within the original basic block. When recording store for RTL DSE, check if the source register is set only once to a constant by a non-partial unconditional load. If yes, record the constant as the constant store source. It eliminates unrolled zero stores after memset 0 in a loop where a vector register is used as the zero store source. gcc/ PR rtl-optimization/105638 * dse.cc (record_store): Use the constant source if the source register is set only once. gcc/testsuite/ PR rtl-optimization/105638 * g++.target/i386/pr105638.C: New test. --- gcc/dse.cc | 22 ++++++++++++ gcc/testsuite/g++.target/i386/pr105638.C | 44 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/g++.target/i386/pr105638.C diff --git a/gcc/dse.cc b/gcc/dse.cc index 30c11cee034..af8e88dac32 100644 --- a/gcc/dse.cc +++ b/gcc/dse.cc @@ -1508,6 +1508,28 @@ record_store (rtx body, bb_info_t bb_info) if (tem && CONSTANT_P (tem)) const_rhs = tem; + else + { + /* If RHS is set only once to a constant, set CONST_RHS + to the constant. */ + df_ref def = DF_REG_DEF_CHAIN (REGNO (rhs)); + if (def != nullptr + && !DF_REF_IS_ARTIFICIAL (def) + && !(DF_REF_FLAGS (def) + & (DF_REF_PARTIAL | DF_REF_CONDITIONAL)) + && !DF_REF_NEXT_REG (def)) + { + rtx_insn *def_insn = DF_REF_INSN (def); + rtx def_body = PATTERN (def_insn); + if (GET_CODE (def_body) == SET) + { + rtx def_src = SET_SRC (def_body); + if (CONSTANT_P (def_src) + && GET_MODE (def_src) == GET_MODE (rhs)) + const_rhs = def_src; + } + } + } } } diff --git a/gcc/testsuite/g++.target/i386/pr105638.C b/gcc/testsuite/g++.target/i386/pr105638.C new file mode 100644 index 00000000000..ff40a459de1 --- /dev/null +++ b/gcc/testsuite/g++.target/i386/pr105638.C @@ -0,0 +1,44 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-std=gnu++20 -O2 -march=skylake" } */ +/* { dg-final { scan-assembler-not "vpxor" } } */ + +#include +#include +#include + +class FastBoard { +public: + typedef std::pair movescore_t; + typedef std::tr1::array scoredlist_t; + +protected: + std::vector m_critical; + + int m_boardsize; +}; + +class FastState { +public: + FastBoard board; + + int movenum; +protected: + FastBoard::scoredlist_t scoredmoves; +}; + +class KoState : public FastState { +private: + std::vector ko_hash_history; + std::vector hash_history; +}; + +class GameState : public KoState { +public: + void foo (); +private: + std::vector game_history; +}; + +void GameState::foo() { + game_history.resize(movenum); +}