[12/13] Use ssizetype selectors for autovectorised VEC_PERM_EXPRs

Message ID 87wp1vjxgq.fsf_-_@linaro.org
State New
Headers show
Series
  • Make VEC_PERM_EXPR work for variable-length vectors
Related show

Commit Message

Richard Sandiford Dec. 9, 2017, 11:25 p.m.
The previous patches mean that there's no reason that constant
VEC_PERM_EXPRs need to have the same shape as the data inputs.
This patch makes the autovectoriser use ssizetype elements instead,
so that indices don't get truncated for large or variable-length vectors.


2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* tree-cfg.c (verify_gimple_assign_ternary): Allow the size of
	the selector elements to be different from the data elements
	if the selector is a VECTOR_CST.
	* tree-vect-stmts.c (vect_gen_perm_mask_any): Use a vector of
	ssizetype for the selector.

Comments

Richard Sandiford Dec. 19, 2017, 8:37 p.m. | #1
Ping

Richard Sandiford <richard.sandiford@linaro.org> writes:
> The previous patches mean that there's no reason that constant

> VEC_PERM_EXPRs need to have the same shape as the data inputs.

> This patch makes the autovectoriser use ssizetype elements instead,

> so that indices don't get truncated for large or variable-length vectors.

>

>

> 2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>

>

> gcc/

> 	* tree-cfg.c (verify_gimple_assign_ternary): Allow the size of

> 	the selector elements to be different from the data elements

> 	if the selector is a VECTOR_CST.

> 	* tree-vect-stmts.c (vect_gen_perm_mask_any): Use a vector of

> 	ssizetype for the selector.

>

> Index: gcc/tree-cfg.c

> ===================================================================

> --- gcc/tree-cfg.c	2017-12-09 22:47:07.103588314 +0000

> +++ gcc/tree-cfg.c	2017-12-09 22:48:58.259216407 +0000

> @@ -4300,8 +4300,11 @@ verify_gimple_assign_ternary (gassign *s

>  	}

>  

>        if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE

> -	  || GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (rhs3_type)))

> -	     != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (rhs1_type))))

> +	  || (TREE_CODE (rhs3) != VECTOR_CST

> +	      && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE

> +				    (TREE_TYPE (rhs3_type)))

> +		  != GET_MODE_BITSIZE (SCALAR_TYPE_MODE

> +				       (TREE_TYPE (rhs1_type))))))

>  	{

>  	  error ("invalid mask type in vector permute expression");

>  	  debug_generic_expr (lhs_type);

> Index: gcc/tree-vect-stmts.c

> ===================================================================

> --- gcc/tree-vect-stmts.c	2017-12-09 22:48:52.268015910 +0000

> +++ gcc/tree-vect-stmts.c	2017-12-09 22:48:58.259216407 +0000

> @@ -6518,11 +6518,12 @@ vectorizable_store (gimple *stmt, gimple

>  tree

>  vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)

>  {

> -  tree mask_elt_type, mask_type;

> +  tree mask_type;

>  

> -  mask_elt_type = lang_hooks.types.type_for_mode

> -    (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);

> -  mask_type = get_vectype_for_scalar_type (mask_elt_type);

> +  unsigned int nunits = sel.length ();

> +  gcc_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));

> +

> +  mask_type = build_vector_type (ssizetype, nunits);

>    return vec_perm_indices_to_tree (mask_type, sel);

>  }

>
Richard Biener Jan. 2, 2018, 1:09 p.m. | #2
On Sun, Dec 10, 2017 at 12:25 AM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> The previous patches mean that there's no reason that constant

> VEC_PERM_EXPRs need to have the same shape as the data inputs.

> This patch makes the autovectoriser use ssizetype elements instead,

> so that indices don't get truncated for large or variable-length vectors.


Ok.

Richard.

>

> 2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>

>

> gcc/

>         * tree-cfg.c (verify_gimple_assign_ternary): Allow the size of

>         the selector elements to be different from the data elements

>         if the selector is a VECTOR_CST.

>         * tree-vect-stmts.c (vect_gen_perm_mask_any): Use a vector of

>         ssizetype for the selector.

>

> Index: gcc/tree-cfg.c

> ===================================================================

> --- gcc/tree-cfg.c      2017-12-09 22:47:07.103588314 +0000

> +++ gcc/tree-cfg.c      2017-12-09 22:48:58.259216407 +0000

> @@ -4300,8 +4300,11 @@ verify_gimple_assign_ternary (gassign *s

>         }

>

>        if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE

> -         || GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (rhs3_type)))

> -            != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (rhs1_type))))

> +         || (TREE_CODE (rhs3) != VECTOR_CST

> +             && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE

> +                                   (TREE_TYPE (rhs3_type)))

> +                 != GET_MODE_BITSIZE (SCALAR_TYPE_MODE

> +                                      (TREE_TYPE (rhs1_type))))))

>         {

>           error ("invalid mask type in vector permute expression");

>           debug_generic_expr (lhs_type);

> Index: gcc/tree-vect-stmts.c

> ===================================================================

> --- gcc/tree-vect-stmts.c       2017-12-09 22:48:52.268015910 +0000

> +++ gcc/tree-vect-stmts.c       2017-12-09 22:48:58.259216407 +0000

> @@ -6518,11 +6518,12 @@ vectorizable_store (gimple *stmt, gimple

>  tree

>  vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)

>  {

> -  tree mask_elt_type, mask_type;

> +  tree mask_type;

>

> -  mask_elt_type = lang_hooks.types.type_for_mode

> -    (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);

> -  mask_type = get_vectype_for_scalar_type (mask_elt_type);

> +  unsigned int nunits = sel.length ();

> +  gcc_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));

> +

> +  mask_type = build_vector_type (ssizetype, nunits);

>    return vec_perm_indices_to_tree (mask_type, sel);

>  }

>

Patch

Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c	2017-12-09 22:47:07.103588314 +0000
+++ gcc/tree-cfg.c	2017-12-09 22:48:58.259216407 +0000
@@ -4300,8 +4300,11 @@  verify_gimple_assign_ternary (gassign *s
 	}
 
       if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
-	  || GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (rhs3_type)))
-	     != GET_MODE_BITSIZE (SCALAR_TYPE_MODE (TREE_TYPE (rhs1_type))))
+	  || (TREE_CODE (rhs3) != VECTOR_CST
+	      && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
+				    (TREE_TYPE (rhs3_type)))
+		  != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
+				       (TREE_TYPE (rhs1_type))))))
 	{
 	  error ("invalid mask type in vector permute expression");
 	  debug_generic_expr (lhs_type);
Index: gcc/tree-vect-stmts.c
===================================================================
--- gcc/tree-vect-stmts.c	2017-12-09 22:48:52.268015910 +0000
+++ gcc/tree-vect-stmts.c	2017-12-09 22:48:58.259216407 +0000
@@ -6518,11 +6518,12 @@  vectorizable_store (gimple *stmt, gimple
 tree
 vect_gen_perm_mask_any (tree vectype, const vec_perm_indices &sel)
 {
-  tree mask_elt_type, mask_type;
+  tree mask_type;
 
-  mask_elt_type = lang_hooks.types.type_for_mode
-    (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))).require (), 1);
-  mask_type = get_vectype_for_scalar_type (mask_elt_type);
+  unsigned int nunits = sel.length ();
+  gcc_assert (nunits == TYPE_VECTOR_SUBPARTS (vectype));
+
+  mask_type = build_vector_type (ssizetype, nunits);
   return vec_perm_indices_to_tree (mask_type, sel);
 }