With bools we can have the usual mismatch between mask and data
use.  Catch that, like we do elsewhere.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

        PR tree-optimization/121194
        * tree-vect-loop.cc (vectorizable_lc_phi): Verify
        vector types are compatible.

        * gcc.dg/torture/pr121194.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr121194.c | 17 +++++++++++++++++
 gcc/tree-vect-loop.cc                   | 12 ++++++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr121194.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr121194.c 
b/gcc/testsuite/gcc.dg/torture/pr121194.c
new file mode 100644
index 00000000000..20f5ff7184f
--- /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 24b0720f2e1..0c1aadac39b 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -8760,6 +8760,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;
 }
-- 
2.43.0

Reply via email to