]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/122577 - missed vectorization of conversion from bool master trunk
authorRichard Biener <rguenther@suse.de>
Thu, 6 Nov 2025 13:24:34 +0000 (14:24 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 7 Nov 2025 13:20:26 +0000 (14:20 +0100)
We are currently overly restrictive with rejecting conversions from
bit-precision entities to mode precision ones.  Similar to RTL expansion
we can focus on non-bit operations producing bit-precision results
which we currently do not properly handle by masking.  Such checks
should be already present.  The following relaxes vectorizable_conversion.

Actual bitfield accesses are catched and rejected by vectorizer dataref
analysis and converted during if-conversion into mode-size accesses
with appropriate sign- or zero-extension.

PR tree-optimization/122577
* tree-vect-stmts.cc (vectorizable_conversion): Allow conversions
from non-mode-precision types.

* gcc.dg/vect/vect-bool-3.c: New testcase.

gcc/testsuite/gcc.dg/vect/vect-bool-3.c [new file with mode: 0644]
gcc/tree-vect-stmts.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-bool-3.c b/gcc/testsuite/gcc.dg/vect/vect-bool-3.c
new file mode 100644 (file)
index 0000000..671f602
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target vect_int } */
+/* { dg-require-effective-target vect_unpack } */
+
+int count_true(const bool *values, int len)
+{
+  int count = 0;
+  for (int i = 0; i < len; i++)
+    count += values[i];
+  return count;
+}
+
+/* { dg-final { scan-tree-dump "optimized: loop vectorized" "vect" } } */
index 83acbb3ff67ccdd4a39606850a23f483d6a4b1fb..8692d440a7cb18d3e99b57093af18aa99cc2965c 100644 (file)
@@ -5282,15 +5282,12 @@ vectorizable_conversion (vec_info *vinfo,
     return false;
 
   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
-      && ((INTEGRAL_TYPE_P (lhs_type)
-          && !type_has_mode_precision_p (lhs_type))
-         || (INTEGRAL_TYPE_P (rhs_type)
-             && !type_has_mode_precision_p (rhs_type))))
+      && INTEGRAL_TYPE_P (lhs_type)
+      && !type_has_mode_precision_p (lhs_type))
     {
       if (dump_enabled_p ())
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                         "type conversion to/from bit-precision unsupported."
-                         "\n");
+                        "type conversion to bit-precision unsupported\n");
       return false;
     }