]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122885 - avoid re-using accumulator for some bool vectors
authorRichard Biener <rguenther@suse.de>
Thu, 27 Nov 2025 09:04:19 +0000 (10:04 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 27 Nov 2025 10:26:11 +0000 (11:26 +0100)
When boolean vectors do not use vector integer modes we are not
set up to produce the partial epilog in a correctly typed way,
so avoid this situation.  For the integer mode case we are able
to pun things correctly, so keep that working.

PR tree-optimization/122885
* tree-vect-loop.cc (vect_find_reusable_accumulator): Reject
mask vectors which do not use integer vector modes.
(vect_create_partial_epilog): Assert the same.

* gcc.dg/torture/pr122873.c: New testcase.

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr122873.c b/gcc/testsuite/gcc.dg/torture/pr122873.c
new file mode 100644 (file)
index 0000000..1eadcee
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv9-a -msve-vector-bits=128" { target { aarch64-*-* } } } */
+/* { dg-additional-options "-mavx512bw -mavx512vl --param vect-partial-vector-usage=1" { target { avx512bw && avx512vl } } } */
+
+char *b;
+bool c(int l)
+{
+  bool d = true;
+  for (int a = 0; a < l; a++)
+    if (b[a])
+      d = false;
+  return d;
+}
index fe78107fe04c9da0ab6dca17747ba3a81591c1a9..ab6c0f084703d38d8f531fbb1c12ac16a4f6cdbf 100644 (file)
@@ -5026,6 +5026,12 @@ vect_find_reusable_accumulator (loop_vec_info loop_vinfo,
   if (VECT_REDUC_INFO_TYPE (reduc_info) != TREE_CODE_REDUCTION)
     return false;
 
+  /* We are not set up to handle vector bools when they are not mapped
+     to vector integer data types.  */
+  if (VECTOR_BOOLEAN_TYPE_P (vectype)
+      && GET_MODE_CLASS (TYPE_MODE (vectype)) != MODE_VECTOR_INT)
+    return false;
+
   unsigned int num_phis = VECT_REDUC_INFO_INITIAL_VALUES (reduc_info).length ();
   auto_vec<tree, 16> main_loop_results (num_phis);
   auto_vec<tree, 16> initial_values (num_phis);
@@ -5126,6 +5132,9 @@ static tree
 vect_create_partial_epilog (tree vec_def, tree vectype, code_helper code,
                            gimple_seq *seq)
 {
+  gcc_assert (!VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (vec_def))
+             || (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (vec_def)))
+                 == MODE_VECTOR_INT));
   unsigned nunits = TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec_def)).to_constant ();
   unsigned nunits1 = TYPE_VECTOR_SUBPARTS (vectype).to_constant ();
   tree stype = TREE_TYPE (vectype);