]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/123528 - tighten bool pattern check
authorRichard Biener <rguenther@suse.de>
Mon, 12 Jan 2026 12:55:07 +0000 (13:55 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 12 Jan 2026 14:39:19 +0000 (15:39 +0100)
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.

gcc/testsuite/gcc.dg/vect/vect-pr12358.c [new file with mode: 0644]
gcc/tree-vect-patterns.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr12358.c b/gcc/testsuite/gcc.dg/vect/vect-pr12358.c
new file mode 100644 (file)
index 0000000..2b42e2f
--- /dev/null
@@ -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;
+}
index bfef31bfabf13574294fd04ac7154cb93d1ae9a0..97130206a2142a1b14d3858ccdc2345220345b0d 100644 (file)
@@ -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));