https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118529
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> --- On Fri, 17 Jan 2025, tnfchris at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118529 > > --- Comment #5 from Tamar Christina <tnfchris at gcc dot gnu.org> --- > (In reply to Richard Biener from comment #4) > > Confirmed. > > OTOH the initial choice of mask mode for the compare by the vectorizer > > is a bit odd. We get there from vect_recog_bool_pattern handling > > > > _28 = _24 ? 0 : _20; > > > > which builds > > > > patt_15 = _24 != 0; > > > > but assigns that a vector truth type based on '_24' rather than on '_28' > > which is where it's going to be used. Using get_mask_type_for_scalar_type > > is also more likely off. > > > > _28 would be wrong no? As the results of patt_15 should be used inside the > conditional. Yes, I only showed the original COND. > The bool recog pattern should be trying to convert _24 into a boolean of the > same precision as it wasn't one, and it's vectorization of _28 that should > handle the mismatch. > > It has to since if the precision of _24 and _28 don't match and you make the > boolean mask based on _28 the compare would have to convert to boolean & > widen/truncate which we don't support and throws off VF detection. > > That's why the pattern does this today and leaves the precision conversion to > later so that analysis sees it needs to happen. The pattern oddly chooses the mask vector type for patt_15 based on the type of _24 - but we are trying to build a mask for the COND so the mask vector type should be built based on _28. With diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 5aebf950548..eed2b1f8c6c 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -5597,11 +5597,7 @@ vect_recog_bool_pattern (vec_info *vinfo, pattern_stmt = gimple_build_assign (lhs_var, NE_EXPR, var, build_zero_cst (TREE_TYPE (var))); - tree new_vectype = get_mask_type_for_scalar_type (vinfo, TREE_TYPE (var)); - if (!new_vectype) - return NULL; - - new_vectype = truth_type_for (new_vectype); + tree new_vectype = truth_type_for (vectype); append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, new_vectype, TREE_TYPE (var)); we're a bit closer to that but then vect_get_vector_types_for_stmt again looks at the compare in isolation and wrecks things, using ->mask_precision which we fail to appropriately set here. This is all quite a mess, and pattern recog should not commit to any vector types anyway.