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.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
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 | 13 +++++++++++++
gcc/tree-vect-stmts.cc | 9 +++------
2 files changed, 16 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-bool-3.c
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 00000000000..671f6029d7d
--- /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 1810efd47d5..3e98f2e0198 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;
}
--
2.51.0