From: Richard Biener Date: Wed, 22 Oct 2025 08:05:01 +0000 (+0200) Subject: tree-optimization/122370 - ICE with reduction and masks X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=065b4476c8611549a07cae58786b844ae5763eaf;p=thirdparty%2Fgcc.git tree-optimization/122370 - ICE with reduction and masks The following fixes bad interaction with mask demotion to data and the code dealing with UB on signed reductions by making sure to also update compute_vectype when updating vectype. PR tree-optimization/122370 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Also update compute_vectype when demoting masks to an integer vector. * gcc.dg/vect/vect-pr122370.c: New testcase. --- diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr122370.c b/gcc/testsuite/gcc.dg/vect/vect-pr122370.c new file mode 100644 index 00000000000..8e536bfb7c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-pr122370.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-mavx512vl -mavx512bw" { target { avx512vl && avx512bw } } } */ + +bool f(bool splat, bool swizzle_splat, + int *elems, int length) +{ + int input = elems[0]; + for (int i = 0; i < length; i++) + { + if (input != elems[i]) + { + splat = false; + swizzle_splat = false; + } + } + return (splat && swizzle_splat); +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 617018f5aaf..77c9e15601b 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -5616,7 +5616,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, && VECT_REDUC_INFO_VECTYPE_FOR_MASK (reduc_info) && vectype != VECT_REDUC_INFO_VECTYPE_FOR_MASK (reduc_info)) { - vectype = VECT_REDUC_INFO_VECTYPE_FOR_MASK (reduc_info); + compute_vectype = vectype = VECT_REDUC_INFO_VECTYPE_FOR_MASK (reduc_info); gimple_seq stmts = NULL; for (unsigned i = 0; i < reduc_inputs.length (); ++i) reduc_inputs[i] = gimple_build (&stmts, VEC_COND_EXPR, vectype,