https://gcc.gnu.org/g:bc10ba9c33bb0cef335e8e0072e638fd4d404337

commit r16-5080-gbc10ba9c33bb0cef335e8e0072e638fd4d404337
Author: Richard Biener <[email protected]>
Date:   Thu Nov 6 14:24:34 2025 +0100

    tree-optimization/122577 - missed vectorization of conversion from bool
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-bool-3.c | 13 +++++++++++++
 gcc/tree-vect-stmts.cc                  |  9 +++------
 2 files changed, 16 insertions(+), 6 deletions(-)

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
index 000000000000..671f6029d7d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-bool-3.c
@@ -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" } } */
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index 83acbb3ff67c..8692d440a7cb 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -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;
     }

Reply via email to