https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124068

            Bug ID: 124068
           Summary: vect_recog_over_widening_pattern fails to perform
                    target check
           Product: gcc
           Version: 16.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_recog_over_widening_pattern happily turns a vector int << int operation
into a vector short << short even when that is not supported.  This can be
seen when testing gcc.dg/vect/pr121949_1.c with -mavx2 which supports
variable shift with SImode but not HImode (AVX512BW is required for this).

Of course pattern detection has no idea whether we'll be doing a vector by
scalar or a vector by vector shift.  Vector by scalar shift is supported
with SSE already.

The following adds such check, but it will regress the vector-by-scalar case
(heuristically a check for external/constant def would be possible, not
considering SLP)

diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index 97130206a21..34c6bc00450 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -3167,7 +3167,10 @@ vect_recog_over_widening_pattern (vec_info *vinfo,
      where beneficial.  */
   tree new_vectype = get_vectype_for_scalar_type (vinfo, new_type);
   tree op_vectype = get_vectype_for_scalar_type (vinfo, op_type);
-  if (!new_vectype || !op_vectype)
+  optab optab1;
+  if (!new_vectype || !op_vectype
+      || !(optab1 = optab_for_tree_code (code, op_vectype, optab_vector))
+      || !can_implement_p (optab1, TYPE_MODE (op_vectype)))
     return NULL;

   if (dump_enabled_p ())

Reply via email to