middle-end/105049 - fix uniform_vector_p and vector CTOR gimplification
authorRichard Biener <rguenther@suse.de>
Fri, 25 Mar 2022 07:43:45 +0000 (08:43 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 25 Mar 2022 12:15:37 +0000 (13:15 +0100)
We have

  return VIEW_CONVERT_EXPR<U>( VEC_PERM_EXPR < {<<< Unknown tree: compound_literal_expr
        V D.1984 = { 0 }; >>>, { 0 }} , {<<< Unknown tree: compound_literal_expr
        V D.1985 = { 0 }; >>>, { 0 }} , { 0, 0 } >  & {(short int) SAVE_EXPR <c>, (short int) SAVE_EXPR <c>});

where we gimplify the init CTORs to

  _1 = {{ 0 }, { 0 }};
  _2 = {{ 0 }, { 0 }};

instead of to vector constants.  That later runs into a bug in
uniform_vector_p which doesn't handle CTORs of vector elements
correctly.

The following adjusts uniform_vector_p to handle CTORs of vector
elements.

2022-03-25  Richard Biener  <rguenther@suse.de>

PR middle-end/105049
* tree.cc (uniform_vector_p): Recurse for VECTOR_CST or
CONSTRUCTOR first elements.

* gcc.dg/pr105049.c: New testcase.

gcc/testsuite/gcc.dg/pr105049.c [new file with mode: 0644]
gcc/tree.cc

diff --git a/gcc/testsuite/gcc.dg/pr105049.c b/gcc/testsuite/gcc.dg/pr105049.c
new file mode 100644 (file)
index 0000000..b0518c6
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-forwprop" } */
+
+typedef short __attribute__((__vector_size__ (sizeof(short)))) V;
+typedef short __attribute__((__vector_size__ (2*sizeof(short)))) U;
+char c;
+
+U
+foo (void)
+{
+  return __builtin_shufflevector ((V){}, (V){}, 0, 0) & c;
+}
index b8017af..ec200e9 100644 (file)
@@ -10266,6 +10266,8 @@ uniform_vector_p (const_tree vec)
       if (i != nelts)
        return NULL_TREE;
 
+      if (TREE_CODE (first) == CONSTRUCTOR || TREE_CODE (first) == VECTOR_CST)
+       return uniform_vector_p (first);
       return first;
     }