https://gcc.gnu.org/g:065b4476c8611549a07cae58786b844ae5763eaf
commit r16-4555-g065b4476c8611549a07cae58786b844ae5763eaf Author: Richard Biener <[email protected]> Date: Wed Oct 22 10:05:01 2025 +0200 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: --- gcc/testsuite/gcc.dg/vect/vect-pr122370.c | 17 +++++++++++++++++ gcc/tree-vect-loop.cc | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) 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 000000000000..8e536bfb7c5f --- /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 617018f5aaf4..77c9e15601b3 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,
