https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103948
--- Comment #6 from Uroš Bizjak <ubizjak at gmail dot com> --- (In reply to Richard Biener from comment #5) > I guess that tree-vect-generic.c is not up-to-date with gimple-isel.cc. We > should probably somehow factor out relevant pieces. > > Note vector lowering will see > > _1 = a_2(D) > b_3(D); > _4 = VEC_COND_EXPR <_1, { -1, -1 }, { 0, 0 }>; > > and clearly a > > if (expand_vec_cond_expr_p (type, TREE_TYPE (a1), code)) > > that's just type/code based cannot know expanding just a comparison will > work fine. It does look like expand_vector_condition from vector lowering > needs > some work. Maybe the following works though: > > diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c > index 6afb6999cd7..5814a71a5bb 100644 > --- a/gcc/tree-vect-generic.c > +++ b/gcc/tree-vect-generic.c > @@ -1052,7 +1052,9 @@ expand_vector_condition (gimple_stmt_iterator *gsi, > bitmap dce_ssa_names) > } > } > > - if (expand_vec_cond_expr_p (type, TREE_TYPE (a1), code)) > + if (expand_vec_cond_expr_p (type, TREE_TYPE (a1), code) > + || (integer_all_onesp (b) && integer_zerop (c) > + && expand_vec_cmp_expr_p (type, TREE_TYPE (a1), code))) > { > gcc_assert (TREE_CODE (a) == SSA_NAME || TREE_CODE (a) == VECTOR_CST); > return true; > > obviously missing would be the case > cmp ? { 0, 0 } : { -1, -1 } via code inversion, not sure if we canonicalize > that way already and not sure if expansion later will pick that up correctly. > > A vector mode with just vec_cmp and not vcond will be good to have to cover > all this with testcases ... ;) > > If the above works it's pre-approved. Using the patch from Comment #2, the following testcase from Comment #0 can be used: --cut here-- typedef signed char vec __attribute__((vector_size(2))); vec lt (vec a, vec b) { return a < b; } --cut here-- vectorizes with -msse4 and fails to vectorize with -msse2. I'll try your proposed patch from Comment #5 later today and report here.