https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110221

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-11-10
                 CC|                            |rsandifo at gcc dot gnu.org
             Blocks|                            |53947

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
So in this case the stmt requiring the loop mask is only "indirectly" invariant
as the mask itself is inside of the loop but with invariant operands.

What works is avoiding to schedule internal def vectorized stmts outside of the
loop.  That will then leave possible invariant motion to the LIM pass, at
least when no loop masking/len is required.  So I'm testing the following.

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 3e5814c3a31..80e279d8f50 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -9081,6 +9081,16 @@ vect_schedule_slp_node (vec_info *vinfo,
       /* Emit other stmts after the children vectorized defs which is
         earliest possible.  */
       gimple *last_stmt = NULL;
+      if (auto loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
+       if (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
+           || LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo))
+         {
+           /* But avoid scheduling internal defs outside of the loop when
+              we might have only implicitly tracked loop mask/len defs.  */
+           gimple_stmt_iterator si
+             = gsi_after_labels (LOOP_VINFO_LOOP (loop_vinfo)->header);
+           last_stmt = *si;
+         }
       bool seen_vector_def = false;
       FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
        if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

Reply via email to