On June 4, 2021 10:44:42 AM GMT+02:00, Jakub Jelinek <ja...@redhat.com> wrote:
>Hi!
>
>The callers of fold_read_from_vector expect that the index they pass is
>an index of an element in the vector and the function does that most of
>the
>time.  But we allow CONSTRUCTORs with VECTOR_TYPE to have VECTOR_TYPE
>elements and in that case every CONSTRUCTOR element represents not just
>one
>index (with the exception of V1 vectors), but multiple.
>So returning zero vector if i >= CONSTRUCTOR_NELTS or returning some
>CONSTRUCTOR_ELT's value might not be what the callers expect.
>
>Fixed by punting if the first element has vector type.
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
>In theory we could instead recurse (and assert that for CONSTRUCTORs of
>vector elements we have always all elements specified like tree-cfg.c
>verifies?) after adjusting the index appropriately.

I think we do this in the corresponding BIT_FIELD_REF match.pd rule. 

Note I don't think we allow CONSTRUCTOR (as in GENERIC) elements, so you'd only 
see SSA names with vector type here? 

Richard. 

>2021-06-04  Jakub Jelinek  <ja...@redhat.com>
>
>       PR target/100887
>       * fold-const.c (fold_read_from_vector): Return NULL if trying to
>       read from a CONSTRUCTOR with vector type elements.
>
>       * gcc.dg/pr100887.c: New test.
>
>--- gcc/fold-const.c.jj        2021-05-28 11:03:19.507884088 +0200
>+++ gcc/fold-const.c   2021-06-03 14:52:52.616393656 +0200
>@@ -15471,6 +15471,9 @@ fold_read_from_vector (tree arg, poly_ui
>       return VECTOR_CST_ELT (arg, i);
>       else if (TREE_CODE (arg) == CONSTRUCTOR)
>       {
>+        if (CONSTRUCTOR_NELTS (arg)
>+            && VECTOR_TYPE_P (TREE_TYPE (CONSTRUCTOR_ELT (arg, 0)->value)))
>+          return NULL_TREE;
>         if (i >= CONSTRUCTOR_NELTS (arg))
>           return build_zero_cst (TREE_TYPE (TREE_TYPE (arg)));
>         return CONSTRUCTOR_ELT (arg, i)->value;
>--- gcc/testsuite/gcc.dg/pr100887.c.jj 2021-06-03 15:09:07.629898248
>+0200
>+++ gcc/testsuite/gcc.dg/pr100887.c    2021-06-03 15:09:48.265335283 +0200
>@@ -0,0 +1,14 @@
>+/* PR target/100887 */
>+/* { dg-do compile } */
>+/* { dg-options "" } */
>+/* { dg-additional-options "-mavx512f" { target { i?86-*-* x86_64-*-*
>} } } */
>+
>+typedef unsigned long long __attribute__((__vector_size__ (2 * sizeof
>(long long)))) U;
>+typedef unsigned long long __attribute__((__vector_size__ (4 * sizeof
>(long long)))) V;
>+typedef unsigned long long __attribute__((__vector_size__ (8 * sizeof
>(long long)))) W;
>+
>+U
>+foo (V v)
>+{
>+  return __builtin_shufflevector ((W){}, v, 0, 8);
>+}
>
>       Jakub

Reply via email to