From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id E4D7E3858D1E for ; Sat, 21 May 2022 03:01:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4D7E3858D1E Received: by mail-pg1-x533.google.com with SMTP id h186so9184073pgc.3 for ; Fri, 20 May 2022 20:01:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=mSjw9eeREXv5ELL5dk3Pmvx3+fk3bX59pOG6N7E45eM=; b=oduFi6wlnknNdnPq+PR9jrUMiJTY9KKbyaiiySLrUY0WOtiMjwo8fMCm/DIY2ZQmBI B2+3s0kRJu+jfr0ekg4RYKpOFzyPXAxRJlUErcfq3EA1nD9zCPfuWl/JfKWo1Pas5RTV YP4jZMUtXU3de7UCNKEjy4JvaQX/it7IF6sDJyCOioAk/2iGDfbPnHqdAUjDINpSXGSK fg6i/3pbBYLxyBr9Vhfj6DTXfipOip7rSB9NNozALIX9/bTjPwN0W5VmL/qY5CEjFF/A hLkOTDWE4fyIWF13ZSKgOrjYMpHIMdLlDzR3N65GuXls8jPPhaiizJthr/Yf2mu7NVRn hU3Q== X-Gm-Message-State: AOAM530dBbRH2CfWOY3oint2iIXzGK6VhZmABQ6a+lBidvwURlborMFK OTThtAVlaO7X5oiC4LR/KZckL1eWnJg= X-Google-Smtp-Source: ABdhPJxWYEaySUwLI+CoBKjKYvtFwGB9nmx/XidA+OSsn7wX7ydhrP6rqHYHg0JKCL/eO1+wU21AIA== X-Received: by 2002:a62:3881:0:b0:4b0:b1c:6fd9 with SMTP id f123-20020a623881000000b004b00b1c6fd9mr13114980pfa.27.1653102082448; Fri, 20 May 2022 20:01:22 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.88.122]) by smtp.gmail.com with ESMTPSA id o16-20020a17090ac09000b001d77f392280sm2590670pjs.30.2022.05.20.20.01.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 20:01:22 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id AD16AC0337 for ; Fri, 20 May 2022 20:01:20 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: [PATCH] DSE: Use the constant source if possible Date: Fri, 20 May 2022 20:01:20 -0700 Message-Id: <20220521030120.1977551-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3028.2 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-List-Received-Date: Sat, 21 May 2022 03:01:25 -0000 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; + } + } + } } } 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); +} -- 2.36.1