SSCV: Add LEN_MASK_STORE into SCCVN

Message ID 20230626023735.1013441-1-juzhe.zhong@rivai.ai
State Unresolved
Headers
Series SSCV: Add LEN_MASK_STORE into SCCVN |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

juzhe.zhong@rivai.ai June 26, 2023, 2:37 a.m. UTC
  From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>

Hi, this patch is to add LEN_MASK_STORE into SCCVN.

LEN_MASK_STORE is predicated by both len and mask together.
My understanding is that LEN_MASK_STORE has same rhs_off and offset as MASK_STORE.
The size = MIN (length (deduced from mask), (len + bias)).

Not sure my understanding it correct or no. 
Hope experts (both Richard && Richi) can correct me if I am wrong.

Thanks.

gcc/ChangeLog:

        * tree-ssa-sccvn.cc (vn_reference_lookup_3): Add LEN_MASK_STORE.

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

Comments

Richard Biener June 26, 2023, 8:11 a.m. UTC | #1
On Mon, 26 Jun 2023, juzhe.zhong@rivai.ai wrote:

> From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
> 
> Hi, this patch is to add LEN_MASK_STORE into SCCVN.
> 
> LEN_MASK_STORE is predicated by both len and mask together.
> My understanding is that LEN_MASK_STORE has same rhs_off and offset as MASK_STORE.
> The size = MIN (length (deduced from mask), (len + bias)).
> 
> Not sure my understanding it correct or no. 
> Hope experts (both Richard && Richi) can correct me if I am wrong.
> 
> Thanks.
> 
> gcc/ChangeLog:
> 
>         * tree-ssa-sccvn.cc (vn_reference_lookup_3): Add LEN_MASK_STORE.
> 
> ---
>  gcc/tree-ssa-sccvn.cc | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
> index 11061a374a2..d1629800705 100644
> --- a/gcc/tree-ssa-sccvn.cc
> +++ b/gcc/tree-ssa-sccvn.cc
> @@ -3304,6 +3304,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
>  	  if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
>  	    return (void *)-1;
>  	  break;
> +	case IFN_LEN_MASK_STORE:
> +	  len = gimple_call_arg (call, 2);
> +	  bias = gimple_call_arg (call, 5);
> +	  if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
> +	    return (void *)-1;
> +	  mask = gimple_call_arg (call, internal_fn_mask_index (fn));
> +	  mask = vn_valueize (mask);
> +	  if (TREE_CODE (mask) != VECTOR_CST)
> +	    return (void *)-1;
> +	  break;
>  	default:
>  	  return (void *)-1;
>  	}
> @@ -3379,6 +3389,13 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
>  		      pd.rhs_off = start;
>  		      pd.offset = offset2i + start;
>  		      pd.size = length;
> +		      if (fn == IFN_LEN_MASK_STORE)

can you use if (len != 0) here?

> +			{
> +			  HOST_WIDE_INT len_bitsize
> +			    = (tree_to_uhwi (len) + tree_to_shwi (bias))
> +			      * BITS_PER_UNIT;
> +			  pd.size = length > len_bitsize ? length : len_bitsize;
> +			}
>  		      if (ranges_known_overlap_p (offset, maxsize,
>  						  pd.offset, pd.size))
>  			return data->push_partial_def (pd, set, set,

the code continues with

                      mask_idx++;
                    }
                  while (known_lt (mask_idx, TYPE_VECTOR_SUBPARTS 
(vectype)));

it might be nicer to store TYPE_VECTOR_SUBPARTS in a variable and
trim that on 'len' instead?

Thanks,
Richard.
  

Patch

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 11061a374a2..d1629800705 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -3304,6 +3304,16 @@  vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
 	  if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
 	    return (void *)-1;
 	  break;
+	case IFN_LEN_MASK_STORE:
+	  len = gimple_call_arg (call, 2);
+	  bias = gimple_call_arg (call, 5);
+	  if (!tree_fits_uhwi_p (len) || !tree_fits_shwi_p (bias))
+	    return (void *)-1;
+	  mask = gimple_call_arg (call, internal_fn_mask_index (fn));
+	  mask = vn_valueize (mask);
+	  if (TREE_CODE (mask) != VECTOR_CST)
+	    return (void *)-1;
+	  break;
 	default:
 	  return (void *)-1;
 	}
@@ -3379,6 +3389,13 @@  vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
 		      pd.rhs_off = start;
 		      pd.offset = offset2i + start;
 		      pd.size = length;
+		      if (fn == IFN_LEN_MASK_STORE)
+			{
+			  HOST_WIDE_INT len_bitsize
+			    = (tree_to_uhwi (len) + tree_to_shwi (bias))
+			      * BITS_PER_UNIT;
+			  pd.size = length > len_bitsize ? length : len_bitsize;
+			}
 		      if (ranges_known_overlap_p (offset, maxsize,
 						  pd.offset, pd.size))
 			return data->push_partial_def (pd, set, set,