Re: [3/4] Make more use of rtx_vector_builder

2018-01-02 Thread Richard Biener
On Thu, Dec 28, 2017 at 9:53 PM, Richard Sandiford
 wrote:
> This patch makes various bits of CONST_VECTOR-building code use
> rtx_vector_builder, operating directly on a specific encoding.

Ok.

Richard.

>
> 2017-12-28  Richard Sandiford  
>
> gcc/
> * expr.c: Include rtx-vector-builder.h.
> (const_vector_mask_from_tree): Use rtx_vector_builder and operate
> directly on the tree encoding.
> (const_vector_from_tree): Likewise.
> * optabs.c: Include rtx-vector-builder.h.
> (expand_vec_perm_var): Use rtx_vector_builder and create a repeating
> sequence of "u" values.
> * vec-perm-indices.c: Include rtx-vector-builder.h.
> (vec_perm_indices_to_rtx): Use rtx_vector_builder and operate
> directly on the vec_perm_indices encoding.
>
> Index: gcc/expr.c
> ===
> --- gcc/expr.c  2017-12-22 12:58:44.518127920 +
> +++ gcc/expr.c  2017-12-22 13:09:48.535709302 +
> @@ -61,6 +61,7 @@ Software Foundation; either version 3, o
>  #include "tree-chkp.h"
>  #include "rtl-chkp.h"
>  #include "ccmp.h"
> +#include "rtx-vector-builder.h"
>
>
>  /* If this is nonzero, we do not bother generating VOLATILE
> @@ -11761,32 +11762,25 @@ try_tablejump (tree index_type, tree ind
>  static rtx
>  const_vector_mask_from_tree (tree exp)
>  {
> -  rtvec v;
> -  unsigned i, units;
> -  tree elt;
> -  machine_mode inner, mode;
> -
> -  mode = TYPE_MODE (TREE_TYPE (exp));
> -  units = VECTOR_CST_NELTS (exp);
> -  inner = GET_MODE_INNER (mode);
> -
> -  v = rtvec_alloc (units);
> +  machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
> +  machine_mode inner = GET_MODE_INNER (mode);
>
> -  for (i = 0; i < units; ++i)
> +  rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
> + VECTOR_CST_NELTS_PER_PATTERN (exp));
> +  unsigned int count = builder.encoded_nelts ();
> +  for (unsigned int i = 0; i < count; ++i)
>  {
> -  elt = VECTOR_CST_ELT (exp, i);
> -
> +  tree elt = VECTOR_CST_ELT (exp, i);
>gcc_assert (TREE_CODE (elt) == INTEGER_CST);
>if (integer_zerop (elt))
> -   RTVEC_ELT (v, i) = CONST0_RTX (inner);
> +   builder.quick_push (CONST0_RTX (inner));
>else if (integer_onep (elt)
>|| integer_minus_onep (elt))
> -   RTVEC_ELT (v, i) = CONSTM1_RTX (inner);
> +   builder.quick_push (CONSTM1_RTX (inner));
>else
> gcc_unreachable ();
>  }
> -
> -  return gen_rtx_CONST_VECTOR (mode, v);
> +  return builder.build ();
>  }
>
>  /* EXP is a VECTOR_CST in which each element is either all-zeros or all-ones.
> @@ -11816,12 +11810,7 @@ const_scalar_mask_from_tree (scalar_int_
>  static rtx
>  const_vector_from_tree (tree exp)
>  {
> -  rtvec v;
> -  unsigned i, units;
> -  tree elt;
> -  machine_mode inner, mode;
> -
> -  mode = TYPE_MODE (TREE_TYPE (exp));
> +  machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
>
>if (initializer_zerop (exp))
>  return CONST0_RTX (mode);
> @@ -11829,27 +11818,25 @@ const_vector_from_tree (tree exp)
>if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
>  return const_vector_mask_from_tree (exp);
>
> -  units = VECTOR_CST_NELTS (exp);
> -  inner = GET_MODE_INNER (mode);
> -
> -  v = rtvec_alloc (units);
> +  machine_mode inner = GET_MODE_INNER (mode);
>
> -  for (i = 0; i < units; ++i)
> +  rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
> + VECTOR_CST_NELTS_PER_PATTERN (exp));
> +  unsigned int count = builder.encoded_nelts ();
> +  for (unsigned int i = 0; i < count; ++i)
>  {
> -  elt = VECTOR_CST_ELT (exp, i);
> -
> +  tree elt = VECTOR_CST_ELT (exp, i);
>if (TREE_CODE (elt) == REAL_CST)
> -   RTVEC_ELT (v, i) = const_double_from_real_value (TREE_REAL_CST (elt),
> -inner);
> +   builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
> + inner));
>else if (TREE_CODE (elt) == FIXED_CST)
> -   RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
> -inner);
> +   builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST 
> (elt),
> + inner));
>else
> -   RTVEC_ELT (v, i) = immed_wide_int_const (wi::to_poly_wide (elt),
> -inner);
> +   builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
> + inner));
>  }
> -
> -  return gen_rtx_CONST_VECTOR (mode, v);
> +  return builder.build ();
>  }
>
>  /* Build a decl for a personality function given a language prefix.  */
> Index: gcc/optabs.c
> 

[3/4] Make more use of rtx_vector_builder

2017-12-28 Thread Richard Sandiford
This patch makes various bits of CONST_VECTOR-building code use
rtx_vector_builder, operating directly on a specific encoding.


2017-12-28  Richard Sandiford  

gcc/
* expr.c: Include rtx-vector-builder.h.
(const_vector_mask_from_tree): Use rtx_vector_builder and operate
directly on the tree encoding.
(const_vector_from_tree): Likewise.
* optabs.c: Include rtx-vector-builder.h.
(expand_vec_perm_var): Use rtx_vector_builder and create a repeating
sequence of "u" values.
* vec-perm-indices.c: Include rtx-vector-builder.h.
(vec_perm_indices_to_rtx): Use rtx_vector_builder and operate
directly on the vec_perm_indices encoding.

Index: gcc/expr.c
===
--- gcc/expr.c  2017-12-22 12:58:44.518127920 +
+++ gcc/expr.c  2017-12-22 13:09:48.535709302 +
@@ -61,6 +61,7 @@ Software Foundation; either version 3, o
 #include "tree-chkp.h"
 #include "rtl-chkp.h"
 #include "ccmp.h"
+#include "rtx-vector-builder.h"
 
 
 /* If this is nonzero, we do not bother generating VOLATILE
@@ -11761,32 +11762,25 @@ try_tablejump (tree index_type, tree ind
 static rtx
 const_vector_mask_from_tree (tree exp)
 {
-  rtvec v;
-  unsigned i, units;
-  tree elt;
-  machine_mode inner, mode;
-
-  mode = TYPE_MODE (TREE_TYPE (exp));
-  units = VECTOR_CST_NELTS (exp);
-  inner = GET_MODE_INNER (mode);
-
-  v = rtvec_alloc (units);
+  machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
+  machine_mode inner = GET_MODE_INNER (mode);
 
-  for (i = 0; i < units; ++i)
+  rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
+ VECTOR_CST_NELTS_PER_PATTERN (exp));
+  unsigned int count = builder.encoded_nelts ();
+  for (unsigned int i = 0; i < count; ++i)
 {
-  elt = VECTOR_CST_ELT (exp, i);
-
+  tree elt = VECTOR_CST_ELT (exp, i);
   gcc_assert (TREE_CODE (elt) == INTEGER_CST);
   if (integer_zerop (elt))
-   RTVEC_ELT (v, i) = CONST0_RTX (inner);
+   builder.quick_push (CONST0_RTX (inner));
   else if (integer_onep (elt)
   || integer_minus_onep (elt))
-   RTVEC_ELT (v, i) = CONSTM1_RTX (inner);
+   builder.quick_push (CONSTM1_RTX (inner));
   else
gcc_unreachable ();
 }
-
-  return gen_rtx_CONST_VECTOR (mode, v);
+  return builder.build ();
 }
 
 /* EXP is a VECTOR_CST in which each element is either all-zeros or all-ones.
@@ -11816,12 +11810,7 @@ const_scalar_mask_from_tree (scalar_int_
 static rtx
 const_vector_from_tree (tree exp)
 {
-  rtvec v;
-  unsigned i, units;
-  tree elt;
-  machine_mode inner, mode;
-
-  mode = TYPE_MODE (TREE_TYPE (exp));
+  machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
 
   if (initializer_zerop (exp))
 return CONST0_RTX (mode);
@@ -11829,27 +11818,25 @@ const_vector_from_tree (tree exp)
   if (VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (exp)))
 return const_vector_mask_from_tree (exp);
 
-  units = VECTOR_CST_NELTS (exp);
-  inner = GET_MODE_INNER (mode);
-
-  v = rtvec_alloc (units);
+  machine_mode inner = GET_MODE_INNER (mode);
 
-  for (i = 0; i < units; ++i)
+  rtx_vector_builder builder (mode, VECTOR_CST_NPATTERNS (exp),
+ VECTOR_CST_NELTS_PER_PATTERN (exp));
+  unsigned int count = builder.encoded_nelts ();
+  for (unsigned int i = 0; i < count; ++i)
 {
-  elt = VECTOR_CST_ELT (exp, i);
-
+  tree elt = VECTOR_CST_ELT (exp, i);
   if (TREE_CODE (elt) == REAL_CST)
-   RTVEC_ELT (v, i) = const_double_from_real_value (TREE_REAL_CST (elt),
-inner);
+   builder.quick_push (const_double_from_real_value (TREE_REAL_CST (elt),
+ inner));
   else if (TREE_CODE (elt) == FIXED_CST)
-   RTVEC_ELT (v, i) = CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
-inner);
+   builder.quick_push (CONST_FIXED_FROM_FIXED_VALUE (TREE_FIXED_CST (elt),
+ inner));
   else
-   RTVEC_ELT (v, i) = immed_wide_int_const (wi::to_poly_wide (elt),
-inner);
+   builder.quick_push (immed_wide_int_const (wi::to_poly_wide (elt),
+ inner));
 }
-
-  return gen_rtx_CONST_VECTOR (mode, v);
+  return builder.build ();
 }
 
 /* Build a decl for a personality function given a language prefix.  */
Index: gcc/optabs.c
===
--- gcc/optabs.c2017-12-22 13:06:03.092620276 +
+++ gcc/optabs.c2017-12-22 13:09:48.535709302 +
@@ -33,6 +33,7 @@ Software Foundation; either version 3, o
 #include "emit-rtl.h"
 #include "recog.h"
 #include "diagnostic-core.h"
+#include "rtx-vector-builder.h"
 
 /* Include