diff mbox series

[11/13] Use vec_perm_builder::series_p in shift_amt_for_vec_perm_mask

Message ID 871sk3lc2y.fsf_-_@linaro.org
State New
Headers show
Series Make VEC_PERM_EXPR work for variable-length vectors | expand

Commit Message

Richard Sandiford Dec. 9, 2017, 11:24 p.m. UTC
This patch makes shift_amt_for_vec_perm_mask use series_p to check
for the simple case of a natural linear series before falling back
to testing each element individually.  The series_p test works with
variable-length vectors but testing every individual element doesn't.


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

gcc/
	* optabs.c (shift_amt_for_vec_perm_mask): Try using series_p
	before testing each element individually.

Comments

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

Richard Sandiford <richard.sandiford@linaro.org> writes:
> This patch makes shift_amt_for_vec_perm_mask use series_p to check
> for the simple case of a natural linear series before falling back
> to testing each element individually.  The series_p test works with
> variable-length vectors but testing every individual element doesn't.
>
>
> 2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>
>
> gcc/
> 	* optabs.c (shift_amt_for_vec_perm_mask): Try using series_p
> 	before testing each element individually.
>
> Index: gcc/optabs.c
> ===================================================================
> --- gcc/optabs.c	2017-12-09 22:48:52.266015836 +0000
> +++ gcc/optabs.c	2017-12-09 22:48:56.257154317 +0000
> @@ -5375,20 +5375,20 @@ vector_compare_rtx (machine_mode cmp_mod
>  static rtx
>  shift_amt_for_vec_perm_mask (machine_mode mode, const vec_perm_indices &sel)
>  {
> -  unsigned int i, first, nelt = GET_MODE_NUNITS (mode);
> +  unsigned int nelt = GET_MODE_NUNITS (mode);
>    unsigned int bitsize = GET_MODE_UNIT_BITSIZE (mode);
> -
> -  first = sel[0];
> +  unsigned int first = sel[0];
>    if (first >= nelt)
>      return NULL_RTX;
> -  for (i = 1; i < nelt; i++)
> -    {
> -      int idx = sel[i];
> -      unsigned int expected = i + first;
> -      /* Indices into the second vector are all equivalent.  */
> -      if (idx < 0 || (MIN (nelt, (unsigned) idx) != MIN (nelt, expected)))
> -	return NULL_RTX;
> -    }
> +
> +  if (!sel.series_p (0, 1, first, 1))
> +    for (unsigned int i = 1; i < nelt; i++)
> +      {
> +	unsigned int expected = i + first;
> +	/* Indices into the second vector are all equivalent.  */
> +	if (MIN (nelt, sel[i]) != MIN (nelt, expected))
> +	  return NULL_RTX;
> +      }
>  
>    return GEN_INT (first * bitsize);
>  }
Richard Biener Jan. 2, 2018, 1:08 p.m. UTC | #2
On Sun, Dec 10, 2017 at 12:24 AM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> This patch makes shift_amt_for_vec_perm_mask use series_p to check
> for the simple case of a natural linear series before falling back
> to testing each element individually.  The series_p test works with
> variable-length vectors but testing every individual element doesn't.

Ok.

Richard.

>
> 2017-12-09  Richard Sandiford  <richard.sandiford@linaro.org>
>
> gcc/
>         * optabs.c (shift_amt_for_vec_perm_mask): Try using series_p
>         before testing each element individually.
>
> Index: gcc/optabs.c
> ===================================================================
> --- gcc/optabs.c        2017-12-09 22:48:52.266015836 +0000
> +++ gcc/optabs.c        2017-12-09 22:48:56.257154317 +0000
> @@ -5375,20 +5375,20 @@ vector_compare_rtx (machine_mode cmp_mod
>  static rtx
>  shift_amt_for_vec_perm_mask (machine_mode mode, const vec_perm_indices &sel)
>  {
> -  unsigned int i, first, nelt = GET_MODE_NUNITS (mode);
> +  unsigned int nelt = GET_MODE_NUNITS (mode);
>    unsigned int bitsize = GET_MODE_UNIT_BITSIZE (mode);
> -
> -  first = sel[0];
> +  unsigned int first = sel[0];
>    if (first >= nelt)
>      return NULL_RTX;
> -  for (i = 1; i < nelt; i++)
> -    {
> -      int idx = sel[i];
> -      unsigned int expected = i + first;
> -      /* Indices into the second vector are all equivalent.  */
> -      if (idx < 0 || (MIN (nelt, (unsigned) idx) != MIN (nelt, expected)))
> -       return NULL_RTX;
> -    }
> +
> +  if (!sel.series_p (0, 1, first, 1))
> +    for (unsigned int i = 1; i < nelt; i++)
> +      {
> +       unsigned int expected = i + first;
> +       /* Indices into the second vector are all equivalent.  */
> +       if (MIN (nelt, sel[i]) != MIN (nelt, expected))
> +         return NULL_RTX;
> +      }
>
>    return GEN_INT (first * bitsize);
>  }
diff mbox series

Patch

Index: gcc/optabs.c
===================================================================
--- gcc/optabs.c	2017-12-09 22:48:52.266015836 +0000
+++ gcc/optabs.c	2017-12-09 22:48:56.257154317 +0000
@@ -5375,20 +5375,20 @@  vector_compare_rtx (machine_mode cmp_mod
 static rtx
 shift_amt_for_vec_perm_mask (machine_mode mode, const vec_perm_indices &sel)
 {
-  unsigned int i, first, nelt = GET_MODE_NUNITS (mode);
+  unsigned int nelt = GET_MODE_NUNITS (mode);
   unsigned int bitsize = GET_MODE_UNIT_BITSIZE (mode);
-
-  first = sel[0];
+  unsigned int first = sel[0];
   if (first >= nelt)
     return NULL_RTX;
-  for (i = 1; i < nelt; i++)
-    {
-      int idx = sel[i];
-      unsigned int expected = i + first;
-      /* Indices into the second vector are all equivalent.  */
-      if (idx < 0 || (MIN (nelt, (unsigned) idx) != MIN (nelt, expected)))
-	return NULL_RTX;
-    }
+
+  if (!sel.series_p (0, 1, first, 1))
+    for (unsigned int i = 1; i < nelt; i++)
+      {
+	unsigned int expected = i + first;
+	/* Indices into the second vector are all equivalent.  */
+	if (MIN (nelt, sel[i]) != MIN (nelt, expected))
+	  return NULL_RTX;
+      }
 
   return GEN_INT (first * bitsize);
 }