On Mon, 30 Sep 2024, Tamar Christina wrote: > > > > Can you explain how you get to see constant/external defs with > > astmt_vec_info? That's somehow a violation of some inherentinvariant in the > > vectorizer. > > > > > > I'm not sure I actually get any. It could be the condition is never hit > > > with a stmt_vec_info. I had assumed however since the condition is part > > > of a gimple_cond and if one of the arguments of the gimple_cond is loop > > > bound, that the condition would be analyzed too. > > > > > > So if you're saying you never get a stmt_vec_info for invariants at this > > > point (I assume you could see you see them in the corresponding slp > > > tree) then maybe checking for the stmt_vec_info is enough. > > > > > > However, when I was looking around for how to check for externals I > > > noticed other patterns also check for externals and constants. So I > > > assumed that you could indeed get them. > > > > You usually check that after doing vect_is_simple_use on the SSA name > > or constant which internally makes all stmts with a stmt_vec_info > > one of the internal def kinds. > > > > So I guess you could do vect_is_simple_use on 'var' as well and check > > the 'dt' it will populate > > > > Ah I see, I did see it being called in some other patterns but wasn't sure > what it > was providing. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master?
OK. Thanks, Richard. > Thanks, > Tamar > > gcc/ChangeLog: > > PR tree-optimization/116817 > * tree-vect-patterns.cc (vect_recog_bool_pattern): Check for const or > externals. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/116817 > * g++.dg/vect/pr116817.cc: New test. > > -- inline copy of patch -- > > diff --git a/gcc/testsuite/g++.dg/vect/pr116817.cc > b/gcc/testsuite/g++.dg/vect/pr116817.cc > new file mode 100644 > index > 0000000000000000000000000000000000000000..7e28982fb138c2cccc4f956aedb03fa454d9d858 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/vect/pr116817.cc > @@ -0,0 +1,16 @@ > +/* { dg-do compile } */ > +/* { dg-additional-options "-O3" } */ > + > +int main_ulData0; > +unsigned *main_pSrcBuffer; > +int main(void) { > + int iSrc = 0; > + bool bData0; > + for (; iSrc < 4; iSrc++) { > + if (bData0) > + main_pSrcBuffer[iSrc] = main_ulData0; > + else > + main_pSrcBuffer[iSrc] = 0; > + bData0 = !bData0; > + } > +} > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > index > e7e877dd2adb55262822f1660f8d92b42d44e6d0..b174ff1e705cec8e7bb414c760eb170ca98222cb > 100644 > --- a/gcc/tree-vect-patterns.cc > +++ b/gcc/tree-vect-patterns.cc > @@ -6062,12 +6062,15 @@ vect_recog_bool_pattern (vec_info *vinfo, > if (get_vectype_for_scalar_type (vinfo, type) == NULL_TREE) > return NULL; > > + enum vect_def_type dt; > if (check_bool_pattern (var, vinfo, bool_stmts)) > var = adjust_bool_stmts (vinfo, bool_stmts, type, stmt_vinfo); > else if (integer_type_for_mask (var, vinfo)) > return NULL; > else if (TREE_CODE (TREE_TYPE (var)) == BOOLEAN_TYPE > - && !vect_get_internal_def (vinfo, var)) > + && vect_is_simple_use (var, vinfo, &dt) > + && (dt == vect_external_def > + || dt == vect_constant_def)) > { > /* If the condition is already a boolean then manually convert it to a > mask of the given integer type but don't set a vectype. */ > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)