https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101801
Bug ID: 101801
Summary: vect_worthwhile_without_simd_p is broken
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
vect_worthwhile_without_simd_p is currently
bool
vect_worthwhile_without_simd_p (vec_info *vinfo, tree_code code)
{
loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo);
unsigned HOST_WIDE_INT value;
return (loop_vinfo
&& LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&value)
&& value >= vect_min_worthwhile_factor (code));
}
which means it's never worthwhile to BB vectorize. Also the VF check
doesn't honor SLP so that a fully SLPed loop with VF == 1 is never
considered worthwhile to vectorize.
I ran into this beast when looking at vectorization of mask condition
operations like cond_mask1 & cond_mask2 which, for AVX512, have
integer mode but vectorizable_operation does
/* Worthwhile without SIMD support? Check only during analysis. */
if (!VECTOR_MODE_P (vec_mode)
&& !vec_stmt
&& !vect_worthwhile_without_simd_p (vinfo, code))
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
"not worthwhile without SIMD support.\n");
return false;
}
and in my case with SLP the VF was indeed one and vectorization failed.
I think the code should not look at the vectorization factor but instead
at the vector type (and its number of components).