public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH V2] DSE: Add LEN_MASK_STORE analysis into DSE
@ 2023-06-26  1:54 juzhe.zhong
  2023-06-26  7:52 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: juzhe.zhong @ 2023-06-26  1:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, rguenther, Ju-Zhe Zhong

From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>

gcc/ChangeLog:

        * tree-ssa-dse.cc (initialize_ao_ref_for_dse): Add LEN_MASK_STORE.
        (dse_optimize_stmt): Ditto.

---
 gcc/tree-ssa-dse.cc | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
index 3c7a2e9992d..b39edd259ab 100644
--- a/gcc/tree-ssa-dse.cc
+++ b/gcc/tree-ssa-dse.cc
@@ -174,6 +174,32 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false)
 	      return true;
 	    }
 	  break;
+	case IFN_LEN_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)
+	      {
+		/* LEN_MASK_STORE is predicated by both mask and len.
+		   We only create ao_ref which is same as MASK_STORE when
+		   (len + bias) is a known INTEGER_CST/POLY_CST value > 0.
+		   Otherwise, we create ao_ref with unknown size.  */
+		tree ele_bytesize
+		  = TYPE_SIZE_UNIT (TREE_TYPE (gimple_call_arg (stmt, 3)));
+		tree ele_num
+		  = int_const_binop (PLUS_EXPR,
+				     gimple_call_arg (stmt, 2),
+				     gimple_call_arg (stmt, 5));
+		tree actual_bytesize = NULL_TREE;
+		if (ele_num && poly_int_tree_p (ele_num)
+		    && known_gt (tree_to_poly_uint64 (ele_num), 0U))
+		  actual_bytesize = ele_bytesize;
+		ao_ref_init_from_ptr_and_size (write, gimple_call_arg (stmt, 0),
+					       actual_bytesize);
+		return true;
+	      }
+	    break;
+	  }
 	default:;
 	}
     }
@@ -1502,6 +1528,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);
-- 
2.36.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] DSE: Add LEN_MASK_STORE analysis into DSE
  2023-06-26  1:54 [PATCH V2] DSE: Add LEN_MASK_STORE analysis into DSE juzhe.zhong
@ 2023-06-26  7:52 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-06-26  7:52 UTC (permalink / raw)
  To: Ju-Zhe Zhong; +Cc: gcc-patches, richard.sandiford

On Mon, 26 Jun 2023, juzhe.zhong@rivai.ai wrote:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
> 
> gcc/ChangeLog:
> 
>         * tree-ssa-dse.cc (initialize_ao_ref_for_dse): Add LEN_MASK_STORE.
>         (dse_optimize_stmt): Ditto.
> 
> ---
>  gcc/tree-ssa-dse.cc | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/gcc/tree-ssa-dse.cc b/gcc/tree-ssa-dse.cc
> index 3c7a2e9992d..b39edd259ab 100644
> --- a/gcc/tree-ssa-dse.cc
> +++ b/gcc/tree-ssa-dse.cc
> @@ -174,6 +174,32 @@ initialize_ao_ref_for_dse (gimple *stmt, ao_ref *write, bool may_def_ok = false)
>  	      return true;
>  	    }
>  	  break;
> +	case IFN_LEN_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)
> +	      {
> +		/* LEN_MASK_STORE is predicated by both mask and len.
> +		   We only create ao_ref which is same as MASK_STORE when
> +		   (len + bias) is a known INTEGER_CST/POLY_CST value > 0.
> +		   Otherwise, we create ao_ref with unknown size.  */
> +		tree ele_bytesize
> +		  = TYPE_SIZE_UNIT (TREE_TYPE (gimple_call_arg (stmt, 3)));
> +		tree ele_num
> +		  = int_const_binop (PLUS_EXPR,
> +				     gimple_call_arg (stmt, 2),
> +				     gimple_call_arg (stmt, 5));

As said there's no guarantee that the length is constant, no?  Please
fix both this and the IFN_LEN_STORE case.

> +		tree actual_bytesize = NULL_TREE;
> +		if (ele_num && poly_int_tree_p (ele_num)
> +		    && known_gt (tree_to_poly_uint64 (ele_num), 0U))
> +		  actual_bytesize = ele_bytesize;
> +		ao_ref_init_from_ptr_and_size (write, gimple_call_arg (stmt, 0),
> +					       actual_bytesize);
> +		return true;
> +	      }
> +	    break;
> +	  }
>  	default:;
>  	}
>      }
> @@ -1502,6 +1528,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);
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-26  7:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26  1:54 [PATCH V2] DSE: Add LEN_MASK_STORE analysis into DSE juzhe.zhong
2023-06-26  7:52 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).