]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121194 - check LC PHIs can be vectorized
authorRichard Biener <rguenther@suse.de>
Mon, 21 Jul 2025 10:48:45 +0000 (12:48 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 21 Jul 2025 13:01:59 +0000 (15:01 +0200)
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.

gcc/testsuite/gcc.dg/torture/pr121194.c [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr121194.c b/gcc/testsuite/gcc.dg/torture/pr121194.c
new file mode 100644 (file)
index 0000000..20f5ff7
--- /dev/null
@@ -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;
+}
index fe11eb72e4bb84870012c9d10a6afbd45b962fdf..899e09dd659b54c4b7f8cd8f5d062795526c7947 100644 (file)
@@ -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;
 }