[gcc r16-6722] tree-optimization/123528 - tighten bool pattern check
Richard Biener
rguenth@gcc.gnu.org
Mon Jan 12 14:39:37 GMT 2026
https://gcc.gnu.org/g:80c314ce497a6d8f5df677b9513f39e6cf85eeac
commit r16-6722-g80c314ce497a6d8f5df677b9513f39e6cf85eeac
Author: Richard Biener <rguenther@suse.de>
Date: Mon Jan 12 13:55:07 2026 +0100
tree-optimization/123528 - tighten bool pattern check
The following makes sure we're only applying bool patterns for
conversions to scalar integer or float types.
PR tree-optimization/123528
* tree-vect-patterns.cc (vect_recog_bool_pattern): Restore
INTEGRAL_TYPE_P check but also allow SCALAR_FLOAT_TYPE_P.
* gcc.dg/vect/vect-pr12358.c: New testcase.
Diff:
---
gcc/testsuite/gcc.dg/vect/vect-pr12358.c | 25 +++++++++++++++++++++++++
gcc/tree-vect-patterns.cc | 4 +++-
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr12358.c b/gcc/testsuite/gcc.dg/vect/vect-pr12358.c
new file mode 100644
index 000000000000..2b42e2f486f6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr12358.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+typedef __attribute__((__vector_size__(1))) char V;
+unsigned char c;
+union {
+ _Bool b;
+ V v;
+} u;
+
+_Complex char *p;
+
+void
+foo()
+{
+ _Bool t = u.b;
+ int t1 = t;
+ char ip = __imag__ *p;
+ char rp = __real__ *p;
+ int t2 = rp;
+ _Bool pp = t1 != t2;
+ _Bool p2 = ip != 0;
+ p2 |= pp;
+ u.b = p2;
+ u.v |= c;
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index bfef31bfabf1..97130206a214 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -6006,7 +6006,9 @@ vect_recog_bool_pattern (vec_info *vinfo,
|| rhs_code == VIEW_CONVERT_EXPR
|| rhs_code == FLOAT_EXPR)
{
- if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (lhs)))
+ if (! (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
+ || SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs)))
+ || VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (lhs)))
return NULL;
vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (lhs));
More information about the Gcc-cvs
mailing list