From patchwork Mon Jun 26 07:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 112754 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7308278vqr; Mon, 26 Jun 2023 00:44:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pk2HEXAAdqFQufJfKSQSE6zH5vcIlJ7n0WxBt56mF7/wuoNSGMmUtptEYExdf0LGY7zP1 X-Received: by 2002:a17:906:db0d:b0:982:80b7:ad4c with SMTP id xj13-20020a170906db0d00b0098280b7ad4cmr21767735ejb.16.1687765459258; Mon, 26 Jun 2023 00:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687765459; cv=none; d=google.com; s=arc-20160816; b=h2UE5hbOdAtRFM0rgNVDjChRIKPPxyf1jS5CsERXreius6W8ojNqUlaQWtXiEyznLL 63v6oxH5S7dq0hXnKjoi7pnWakmEvHcfmLjl/u3c9Sis+XwEd44MbSa6/CEHivXztKI6 2CmK8OVJcFLlx4jPBRELkAdES7Ftkayo6gpk0HLkFWc+gF/F4Sp5V+RamWcajKz7migK hTU6nXUGk3BtAJ/SqMi7CjmIg+ZxMCOFE07mOK7qYueOBL6gleY5srRCWNPYJMa9t5R9 F/HwuidFtU2edB1awJsZ8EFCOr5ECb8ACk2cMya6JmuzdbiBBqen+HgqHfezn1nFj4JJ bdEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=pICGGyGDoZrpIyhLtruMnO2euvGR+K92rPasoSU3dvk=; fh=h6UG6PIw2FD/e8JL+9n/VDDoO75bXx4B3jGj5okR2Rw=; b=WAHPwcEZrRwwYKMW5DJSUvu2u2Gbmsla5UKGMyLAj4fXjokz4yLD8xZbdZw0hkPT+A vr3GVsLfxsmxQOnEQ3bddA4f09W//vKc1ohfYjC/+uIY1Jsz6lTrZf9ynI3S+V7RGI9q NjEcYhrQbHDnlOlwmlEWWNg3065HWTtAYASn0vlTatCFE5/ABnYD9S/EPfExuWZctQBV 7VfvAPbAqKPxhP5huKXCAWL+IoFUCp39sdwfWVyDEoisPZOdilJhP6obVF3Ku7qbPNE3 P6ifNTcaJb81LGCr+3+UiLLsPwKzTCjcIKAdj+b3ylL8pEHsjhYx9Q1PRk+F11gpvn0Y cqnQ== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w21-20020a17090633d500b0098cdd1e26eesi2584836eja.955.2023.06.26.00.44.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 00:44:19 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 218823857701 for ; Mon, 26 Jun 2023 07:44:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by sourceware.org (Postfix) with ESMTPS id 8AE0C3858D33 for ; Mon, 26 Jun 2023 07:43:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8AE0C3858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp81t1687765424tqsrcqlk Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 26 Jun 2023 15:43:43 +0800 (CST) X-QQ-SSF: 01400000000000G0S000000A0000000 X-QQ-FEAT: eSZ1CZgv+JCyeu0m4cxs+13YtpwgDLHI19igTe5d7gowHfHgVMQVB/T9eIWdG v2JTuOoH/qx4nmo+j4+ulQNB5bCmg5Z3DWLgM5e34n7wLAgVH336oCxrabV+mbA1it86eun 7ZkJeNXDm8+Lztc2nV6FiFP/4yozA2SoH4kAnxKDp8X11YkT0CcvllO9kTQxIGc/vvITqOP HZnoICJeC9ZV3dnIc5wx7GDWm1JMtYrFdDVlKzpijpxe6sbSZIRuQvkT480o1ZOy2AAj1xn uK21xDm+TIS9EXyRLK1qTF7+jjf1cYOgq54w3JXRW9UkZr0yi9fv5JT2Hl9pKyxP9fEl4ch JLB6b4M0XDBAYCwbDgIzSwDw21hoojgw1VmzR8wVUYV89IgdWuXy22CC3H7wYQgLeFRJjp6 01EfDJasdsk= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 17092752510874512409 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Ju-Zhe Zhong Subject: [PATCH V3] DSE: Add LEN_MASK_STORE analysis into DSE and fix LEN_STORE Date: Mon, 26 Jun 2023 15:43:42 +0800 Message-Id: <20230626074342.2629716-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769750353923692698?= X-GMAIL-MSGID: =?utf-8?q?1769750353923692698?= From: Ju-Zhe Zhong Hi, Richi. This patch is adding LEN_MASK_STORE into DSE. My understanding is LEN_MASK_STORE is predicated by mask and len. No matter len is constant or not, the ao_ref should be the same as MASK_STORE. Wheras for LEN_STORE, when len is constant, we use (len - bias), otherwise, it's the same as MASK_STORE/LEN_MASK_STORE. Not sure whether I am on the same page with you, feel free to correct me. Thanks. gcc/ChangeLog: * tree-ssa-dse.cc (initialize_ao_ref_for_dse): Add LEN_MASK_STORE and fix LEN_STORE. (dse_optimize_stmt): Add LEN_MASK_STORE. --- gcc/tree-ssa-dse.cc | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc index 3c7a2e9992d..f8338037a61 100644 --- a/gcc/tree-ssa-dse.cc +++ b/gcc/tree-ssa-dse.cc @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-loop-niter.h" #include "cfgloop.h" #include "tree-data-ref.h" +#include "internal-fn.h" /* This file implements dead store elimination. @@ -157,23 +158,36 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false) switch (gimple_call_internal_fn (stmt)) { case IFN_LEN_STORE: - ao_ref_init_from_ptr_and_size - (write, gimple_call_arg (stmt, 0), - int_const_binop (MINUS_EXPR, - gimple_call_arg (stmt, 2), - gimple_call_arg (stmt, 4))); - return true; case IFN_MASK_STORE: - /* We cannot initialize a must-def ao_ref (in all cases) but we - can provide a may-def variant. */ - if (may_def_ok) - { - ao_ref_init_from_ptr_and_size - (write, gimple_call_arg (stmt, 0), - TYPE_SIZE_UNIT (TREE_TYPE (gimple_call_arg (stmt, 3)))); - return true; - } - break; + case IFN_LEN_MASK_STORE: + { + int stored_value_index + = internal_fn_stored_value_index (gimple_call_internal_fn (stmt)); + if (gimple_call_internal_fn (stmt) == IFN_LEN_STORE) + { + tree len = gimple_call_arg (stmt, 2); + tree bias = gimple_call_arg (stmt, 4); + if (tree_fits_uhwi_p (len)) + { + ao_ref_init_from_ptr_and_size (write, + gimple_call_arg (stmt, 0), + int_const_binop (MINUS_EXPR, + len, bias)); + return true; + } + } + /* We cannot initialize a must-def ao_ref (in all cases) but we + can provide a may-def variant. */ + if (may_def_ok) + { + ao_ref_init_from_ptr_and_size ( + write, gimple_call_arg (stmt, 0), + TYPE_SIZE_UNIT ( + TREE_TYPE (gimple_call_arg (stmt, stored_value_index)))); + return true; + } + break; + } default:; } } @@ -1502,6 +1516,7 @@ dse_optimize_stmt (function *fun, gimple_stmt_iterator *gsi, sbitmap live_bytes) { case IFN_LEN_STORE: case IFN_MASK_STORE: + case IFN_LEN_MASK_STORE: { enum dse_store_status store_status; store_status = dse_classify_store (&ref, stmt, false, live_bytes);