[SLP] SLP vectorization: vectorize vector constructors

Joel Hutton Joel.Hutton@arm.com
Wed Oct 30 13:30:00 GMT 2019


On 15/10/2019 13:11, Richard Biener wrote:
 >>  > You miss to check that CONSTRUCTOR_NELTS == TYPE_VECTOR_SUBPARTS
 >>  > (we can have omitted trailing zeros).
 >
 > ^^^
 >
 > I don't see this being handled?  You give up on non-SSA names
 > but not on the omitted trailing zeros.

I had thought checking the number of vectors produced would work. I've 
added that check.
I'm slightly confused about what should be done for non-SSA names. 
There's no scalar stmt to gather for a constant in a vector constructor.

 >
 > You build a CONSTRUCTOR of vectors, thus
 >
 > _orig_ssa_1 = { vect_part1_2, vect_part2_3, ... };
I've added code to do this, and a testcase which triggers it.

 >
 > +
 > +         if (constructor)
 > +           {
 > +             SLP_INSTANCE_ROOT_STMT (new_instance) = stmt_info->stmt;
 > +           }
 > +         else
 > +           SLP_INSTANCE_ROOT_STMT (new_instance) = NULL;
 > +
 >
 > too much vertical space, no {} around single-stmt if clauses
Fixed.

 >
 >
 > @@ -2725,6 +2760,10 @@ vect_bb_slp_scalar_cost (basic_block bb,
 >                 stmt_vec_info use_stmt_info = vinfo->lookup_stmt
 > (use_stmt);
 >                 if (!use_stmt_info || !PURE_SLP_STMT (use_stmt_info))
 >                   {
 > +                   /* Check this is not a constructor that will be
 > vectorized
 > +                      away.  */
 > +                   if (BB_VINFO_GROUPED_STORES (vinfo).contains
 > (use_stmt_info))
 > +                       continue;
 >
 > hmm, so why not set the slp type on SLP_INSTANCE_ROOT_STMT instead?
 > In theory the stmt should be part of the SLP tree itself but that's
 > probably too awkward to be made work at the moment ;)
I did try this, but it was indeed very awkward to be made to work.

 >
 > vect_ssa_use_outside_bb and vect_slp_check_for_constructors are new
 > functions which need comments.
Fixed. I've also taken the 'vectorize the root' out into a separate 
function.

 >
 > +  /* For vector constructors, the same SSA name must be used to 
maintain
 > data
 > +     flow into other basic blocks.  */
 > +  if (instance->root == node && SLP_INSTANCE_ROOT_STMT (instance)
 > +      && SLP_TREE_NUMBER_OF_VEC_STMTS (node) == 1
 > +      && SLP_TREE_VEC_STMTS (node).exists ())
 > +    {
 >
 > it should read
 >
 >   /* Vectorize the instance root.  */
 >
 > and be in vect_schedule_slp after the vect_schedule_slp_instance.
 > As said above you need to handle SLP_TREE_NUMBER_OF_VEC_STMTS > 1,
 > you also cannot simply do "nothing" here, "failing" vectorization
 > (well, you probably can - DCE will remove the vectorized code - but
 > at least if there were calls in the SLP tree they will be mangled
 > by vectorization so the scalar code is wrecked).  SO it should be
 >
 >  if (SLP_INSTANCE_ROOT_STMT (instance))
 >    .. you may not fail to replace the scalar root stmt here ..
 >
So what should be done in the case that CONSTRUCTOR_NELTS < 
TYPE_VECTOR_SUBPARTS?

 > +         if (CONSTRUCTOR_NELTS (rhs) == 0)
 > +           vectorizable = false;
 > +
 >
 > if you use continue; you can elide the 'vectorizable' variable.
Done.

 >
 > +         if (!vect_ssa_use_outside_bb (gimple_assign_lhs (stmt)))
 > +           vectorizable = false;
 > +
 >
 > why's that?  no comments that clarify ;)  The vector may be
 > used as argument to a call or as source of a store.  So I'd simply
 > remove this check (and the function).

Done. The thinking was that if the vector was used as a source of a 
store the SLP tree would be built from the grouped store instead. Will 
it not cause problems if both the grouped store and the vector 
constructor are used to build SLP trees?



2019-10-10  Joel Hutton  <Joel.Hutton@arm.com>

         * expr.c (store_constructor): Add case for constructor of vectors.
         * tree-vect-slp.c (vect_analyze_slp_instance): Add case for vector constructors.
         (vect_bb_slp_scalar_cost): Likewise.
         (vect_slp_check_for_constructors): New function.
         (vect_slp_analyze_bb_1): Add check for vector constructors.
         (vect_schedule_slp_instance): Add case to fixup vector constructor stmt.
         (vectorize_slp_instance_root_stmt): New function
         * tree-vectorizer.h (SLP_INSTANCE_ROOT_STMT): New field.

gcc/testsuite/ChangeLog:

2019-10-10  Joel Hutton  <Joel.Hutton@arm.com>

         * gcc.dg/vect/bb-slp-40.c: New test.
         * gcc.dg/vect/bb-slp-41.c: New test.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-SLP-Vectorization-Vectorize-vector-constructors.patch
Type: text/x-patch
Size: 13814 bytes
Desc:  0001-SLP-Vectorization-Vectorize-vector-constructors.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191030/224a3c4c/attachment.bin>


More information about the Gcc-patches mailing list