https://gcc.gnu.org/g:0f7c27bb0d9c1a7346fc273615c0a103e1f6f8cf

commit r17-5453-g0f7c27bb0d9c1a7346fc273615c0a103e1f6f8cf
Author: Richard Biener <[email protected]>
Date:   Wed Oct 21 07:51:24 2026 +0200

    tree-optimization/127975 - handle missing vector mask type for simd clones
    
    When attempting to vectorize a loop with partial vector usage and a masked
    simd clone with scalar integer mask mode, 
get_related_vectype_for_scalar_type
    can return NULL_TREE if the target does not support a vector mode with the
    required number of elements (such as V2SF on 32-bit x86).  Verify that a
    valid mask type was found and disable partial vectors if not, rather than
    passing a NULL vectype to vect_record_loop_mask and crashing in hash-set.h.
    Also assert in vect_record_loop_mask that vectype is non-null.
    
            PR tree-optimization/127975
            * tree-vect-stmts.cc (vectorizable_simd_clone_call): Disable
            partial vectors if get_related_vectype_for_scalar_type returns
            NULL_TREE for the mask.

Diff:
---
 gcc/tree-vect-stmts.cc | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index b58d974921a4..6e7e948ff1e4 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -4483,8 +4483,8 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
                  if (SCALAR_INT_MODE_P (bestn_inbranch->simdclone->mask_mode))
                    {
                      callee_nelements
-                         = exact_div (bestn_inbranch->simdclone->simdlen,
-                                      
bestn_inbranch->simdclone->args[i].linear_step);
+                       = exact_div (bestn_inbranch->simdclone->simdlen,
+                                    
bestn_inbranch->simdclone->args[i].linear_step);
                      masktype = get_related_vectype_for_scalar_type
                          (vinfo->vector_mode, TREE_TYPE (vectype),
                           callee_nelements);
@@ -4503,10 +4503,22 @@ vectorizable_simd_clone_call (vec_info *vinfo, 
stmt_vec_info stmt_info,
                           TYPE_MODE (masktype));
                      callee_nelements = TYPE_VECTOR_SUBPARTS (masktype);
                    }
-                 auto o = vector_unroll_factor (nunits, callee_nelements);
-                 vect_record_loop_mask (loop_vinfo,
-                                        &LOOP_VINFO_MASKS (loop_vinfo),
-                                        ncopies  * o, masktype, NULL_TREE);
+                 if (!masktype)
+                   {
+                     if (dump_enabled_p ())
+                       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                                        "can't use a fully-masked loop because"
+                                        " no suitable vector type was found 
for"
+                                        " the mask.\n");
+                     LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false;
+                   }
+                 else
+                   {
+                     auto o = vector_unroll_factor (nunits, callee_nelements);
+                     vect_record_loop_mask (loop_vinfo,
+                                            &LOOP_VINFO_MASKS (loop_vinfo),
+                                            ncopies * o, masktype, NULL_TREE);
+                   }
                }
            }
          else if ((bestn->simdclone->args[i].arg_type

Reply via email to