tree-optimization/97732 - fix init of SLP induction vectorization
authorRichard Biener <rguenther@suse.de>
Fri, 6 Nov 2020 08:35:27 +0000 (09:35 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 6 Nov 2020 10:10:23 +0000 (11:10 +0100)
This PR exposes two issues - one that the vector builder treats
&x as eligible for VECTOR_CST elements and one that SLP induction
vectorization forgets to convert init elements to the vector
component type which makes a difference for pointer vs. integer.

2020-11-06  Richard Biener  <rguenther@suse.de>

PR tree-optimization/97732
* tree-vect-loop.c (vectorizable_induction): Convert the
init elements to the vector component type.
* gimple-fold.c (gimple_build_vector): Use CONSTANT_CLASS_P
rather than TREE_CONSTANT to determine if elements are
eligible for VECTOR_CSTs.

* gcc.dg/vect/bb-slp-pr97732.c: New testcase.

gcc/gimple-fold.c
gcc/testsuite/gcc.dg/vect/bb-slp-pr97732.c [new file with mode: 0644]
gcc/tree-vect-loop.c

index c3fa4cb..ca38a31 100644 (file)
@@ -7855,7 +7855,7 @@ gimple_build_vector (gimple_seq *seq, location_t loc,
   gcc_assert (builder->nelts_per_pattern () <= 2);
   unsigned int encoded_nelts = builder->encoded_nelts ();
   for (unsigned int i = 0; i < encoded_nelts; ++i)
-    if (!TREE_CONSTANT ((*builder)[i]))
+    if (!CONSTANT_CLASS_P ((*builder)[i]))
       {
        tree type = builder->type ();
        unsigned int nelts = TYPE_VECTOR_SUBPARTS (type).to_constant ();
diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr97732.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr97732.c
new file mode 100644 (file)
index 0000000..5187090
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+struct S { int a, b; } *e;
+int d;
+
+void
+foo (struct S *x)
+{
+  for (e = x; d; d++, e++)
+    e->a = e->b = (int) (__UINTPTR_TYPE__) e;
+}
index ef2ea3d..0ba3754 100644 (file)
@@ -8001,6 +8001,10 @@ vectorizable_induction (loop_vec_info loop_vinfo,
                {
                  /* The scalar inits of the IVs if not vectorized.  */
                  elt = inits[(ivn*const_nunits + eltn) % group_size];
+                 if (!useless_type_conversion_p (TREE_TYPE (vectype),
+                                                 TREE_TYPE (elt)))
+                   elt = gimple_build (&init_stmts, VIEW_CONVERT_EXPR,
+                                       TREE_TYPE (vectype), elt);
                  init_elts.quick_push (elt);
                }
              /* The number of steps to add to the initial values.  */