]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122370 - ICE with reduction and masks
authorRichard Biener <rguenther@suse.de>
Wed, 22 Oct 2025 08:05:01 +0000 (10:05 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 22 Oct 2025 09:11:04 +0000 (11:11 +0200)
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.

gcc/testsuite/gcc.dg/vect/vect-pr122370.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr122370.c b/gcc/testsuite/gcc.dg/vect/vect-pr122370.c
new file mode 100644 (file)
index 0000000..8e536bf
--- /dev/null
@@ -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);
+}
index 617018f5aaf438680baf5c55f031df78a93cb70b..77c9e15601b3f60da52c7b8899fa0f5c174cad0f 100644 (file)
@@ -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,