https://gcc.gnu.org/g:8ca85e95daca7f7c56d297fa7f2328e5385d446c

commit r16-2381-g8ca85e95daca7f7c56d297fa7f2328e5385d446c
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Jul 21 12:48:45 2025 +0200

    tree-optimization/121194 - check LC PHIs can be vectorized
    
    With bools we can have the usual mismatch between mask and data
    use.  Catch that, like we do elsewhere.
    
            PR tree-optimization/121194
            * tree-vect-loop.cc (vectorizable_lc_phi): Verify
            vector types are compatible.
    
            * gcc.dg/torture/pr121194.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr121194.c | 17 +++++++++++++++++
 gcc/tree-vect-loop.cc                   | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr121194.c 
b/gcc/testsuite/gcc.dg/torture/pr121194.c
new file mode 100644
index 000000000000..20f5ff7184ff
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr121194.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+int a, b, c, d;
+void e() {
+  int *f = &b;
+  for (a = 0; a < 8; a++) {
+    *f = 0;
+    for (c = 0; c < 2; c++)
+      *f = *f == 0;
+  }
+}
+int main() {
+  e();
+  int *g = &b;
+  *g = *g == (d == 0);
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fe11eb72e4bb..899e09dd659b 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -8759,6 +8759,18 @@ vectorizable_lc_phi (loop_vec_info loop_vinfo,
                         "incompatible vector types for invariants\n");
       return false;
     }
+
+  /* ???  This can happen with data vs. mask uses of boolean.  */
+  if (!useless_type_conversion_p (SLP_TREE_VECTYPE (slp_node),
+                                 SLP_TREE_VECTYPE
+                                   (SLP_TREE_CHILDREN (slp_node)[0])))
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "missed mask promotion\n");
+      return false;
+    }
+
   STMT_VINFO_TYPE (stmt_info) = lc_phi_info_type;
   return true;
 }

Reply via email to