From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id 9B7AB3858D37; Mon, 26 Jun 2023 20:57:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B7AB3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687813078; bh=qT9p5hr8hOQomNz7HEg//SChTcDt9ZDKAIEzDUBcq1w=; h=From:To:Subject:Date:From; b=hvEgORyfXafDr8N521TcGo7yT+ZRKGqbX04HCfzUwP7s1GQFFyZpqNvEqtsH1Hfjs yKiYbQaWgHeibhjvBKz3NMIM1aAhaa7zhmuUpYI52GE8gF8h7gum5jHkNd18mGeivf Q71RgBAKtnu9d4U6p3GS54EGA3Ouf8fJKXwOpi0s= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] DSE: Add LEN_MASK_STORE analysis into DSE and fix LEN_STORE X-Act-Checkin: gcc X-Git-Author: Ju-Zhe Zhong X-Git-Refname: refs/vendors/riscv/heads/gcc-13-with-riscv-opts X-Git-Oldrev: cfa303b682f37c2fe6e0ef6cd7c135a9ee84b884 X-Git-Newrev: f36a9241ab1b110caaecd6b795d5e9d4a28dadea Message-Id: <20230626205758.9B7AB3858D37@sourceware.org> Date: Mon, 26 Jun 2023 20:57:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f36a9241ab1b110caaecd6b795d5e9d4a28dadea commit f36a9241ab1b110caaecd6b795d5e9d4a28dadea Author: Ju-Zhe Zhong Date: Mon Jun 26 15:43:42 2023 +0800 DSE: Add LEN_MASK_STORE analysis into DSE and fix LEN_STORE 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. Diff: --- 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 eabe8ba4522..95ace407ddb 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:; } } @@ -1483,6 +1497,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);