Re: [PATCH 1/2] Add vect_finish_stmt_generation for sequences

Andrea Pinski <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CALvbMcDwVHzxtqn6sm-zsBPRCTbC3x-5cCLGpwNEyYbBsj_5HQ@mail.gmail.com>
On Sat, Aug 15, 2026 at 11:01 PM H.J. Lu <[email protected]> wrote:
>
> On Sun, Aug 16, 2026 at 6:36 AM H.J. Lu <[email protected]> wrote:
> >
> > On Fri, Aug 14, 2026 at 8:13 PM Richard Biener <[email protected]> wrote:
> > >
> > > The following attempts to make using gimple_build easier during
> > > vectorizer code generation by providing an overload of
> > > vect_finish_stmt_generation that handles a built sequence.
> > > In addition to inserting and finishing stmts on the sequence the
> > > ultimate result is made to be based on the passed vectorizer
> > > temporary (that gets us the fancy names).
> > >
> > > I have converted one instance in vectorizable_conversion which
> > > I'll need to handle both NOP_EXPR and VIEW_CONVERT_EXPR which
> > > gimple_build happily does correctly, but vect_gimple_build does
> > > not.
> > >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu.
> > >
> > > Does this look sensible?  I can of course sepecial-case
> > > VIEW_CONVERT_EXPR manually as well.
> > >
> > >         * tree-vect-stmts.cc (vect_finish_stmt_generation): New
> > >         overload for gimple_build sequences.
> > >         (vectorizable_conversion): Convert one instance of
> > >         vect_gimple_build to gimple_build plus
> > >         vect_finish_stmt_generation.
> > > ---
> > >  gcc/tree-vect-stmts.cc | 43 ++++++++++++++++++++++++++++++++----------
> > >  1 file changed, 33 insertions(+), 10 deletions(-)
> > >
> > > diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> > > index a023977bc51..44090015e7a 100644
> > > --- a/gcc/tree-vect-stmts.cc
> > > +++ b/gcc/tree-vect-stmts.cc
> > > @@ -1260,7 +1260,7 @@ vect_get_vec_defs (vec_info *, slp_tree slp_node,
> > >
> > >  /* Helper function called by vect_finish_replace_stmt and
> > >     vect_finish_stmt_generation.  Set the location of the new
> > > -   statement and create and return a stmt_vec_info for it.  */
> > > +   statement.  */
> > >
> > >  static void
> > >  vect_finish_stmt_generation_1 (vec_info *,
> > > @@ -1285,8 +1285,7 @@ vect_finish_stmt_generation_1 (vec_info *,
> > >  }
> > >
> > >  /* Replace the scalar statement STMT_INFO with a new vector statement VEC_STMT,
> > > -   which sets the same scalar result as STMT_INFO did.  Create and return a
> > > -   stmt_vec_info for VEC_STMT.  */
> > > +   which sets the same scalar result as STMT_INFO did.  */
> > >
> > >  void
> > >  vect_finish_replace_stmt (vec_info *vinfo,
> > > @@ -1302,7 +1301,7 @@ vect_finish_replace_stmt (vec_info *vinfo,
> > >  }
> > >
> > >  /* Add VEC_STMT to the vectorized implementation of STMT_INFO and insert it
> > > -   before *GSI.  Create and return a stmt_vec_info for VEC_STMT.  */
> > > +   before *GSI.  */
> > >
> > >  void
> > >  vect_finish_stmt_generation (vec_info *vinfo,
> > > @@ -1344,6 +1343,31 @@ vect_finish_stmt_generation (vec_info *vinfo,
> > >    vect_finish_stmt_generation_1 (vinfo, stmt_info, vec_stmt);
> > >  }
> > >
> > > +/* Add the stmts in STMTS to the vectorized implementation of STMT_INFO and
> > > +   insert them before *GSI.  Make sure the final stmt has a result
> > > +   based on VAR.  */
> > > +
> > > +void
> > > +vect_finish_stmt_generation (vec_info *vinfo,
> > > +                            stmt_vec_info stmt_info, gimple_seq &stmts,
> > > +                            tree var, gimple_stmt_iterator *gsi)
> > > +{
> > > +  auto si = gsi_start (stmts);
> > > +  while (!gsi_end_p (si))
> > > +    {
> > > +      gimple *new_stmt = gsi_stmt (si);
> > > +      gsi_remove (&si, false);
> > > +      if (gsi_end_p (si))
> > > +       {
> > > +         tree lhs = gimple_get_lhs (new_stmt);
> > > +         gcc_assert (!SSA_NAME_VAR (lhs));
> > > +         SET_SSA_NAME_VAR_OR_IDENTIFIER (lhs, var);
> > > +       }
> > > +      vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
> > > +    }
> > > +}
> > > +
> > > +
> > >  /* We want to vectorize a call to combined function CFN with function
> > >     decl FNDECL, using VECTYPE_OUT as the type of the output and VECTYPE_IN
> > >     as the types of all inputs.  Check whether this is possible using
> > > @@ -5797,12 +5821,11 @@ vectorizable_conversion (vec_info *vinfo,
> > >             }
> > >           else
> > >             {
> > > -             new_stmt = vect_gimple_build (vec_dest, code1, vop0);
> > > -             new_temp = make_ssa_name (vec_dest, new_stmt);
> > > -             gimple_set_lhs (new_stmt, new_temp);
> > > -             vect_finish_stmt_generation (vinfo, stmt_info, new_stmt, gsi);
> > > -
> > > -             slp_node->push_vec_def (new_stmt);
> > > +             gimple_seq stmts = NULL;
> > > +             new_temp = gimple_build (&stmts, code1, vectype_out, vop0);
> > > +             vect_finish_stmt_generation (vinfo, stmt_info,
> > > +                                          stmts, vec_dest, gsi);
> > > +             slp_node->push_vec_def (new_temp);
> > >             }
> > >         }
> > >        break;
> > > --
> > > 2.51.0
> > >
> >
> > I need the patch enclosed here to avoid ICE in 2 testcases included
>
> Here is the updated patch with 3 tests.
>
> > in the patch.   But I got another ICE in bad.c:
> >
> > [hjl@gnu-zen4-1 gcc]$ ./xgcc -B./ -S -O2 -march=x86-64 ~/bugs/gcc/cvise-1/bad.c
> > during GIMPLE pass: thread
> > /export/home/hjl/bugs/gcc/cvise-1/bad.c: In function ‘collate_output___o_2’:
> > /export/home/hjl/bugs/gcc/cvise-1/bad.c:20:1: internal compiler error:
> > Segmentation fault
>
> This is
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126876

The big comment about HJL's patch is `code1 == NOP_EXPR` should be
`CONVERT_EXPR_CODE_P (code1)` instead.

>
>
> --
> H.J.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.