From: Richard Biener Date: Mon, 21 Jul 2025 10:48:45 +0000 (+0200) Subject: tree-optimization/121194 - check LC PHIs can be vectorized X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ca85e95daca7f7c56d297fa7f2328e5385d446c;p=thirdparty%2Fgcc.git 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 --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 fe11eb72e4b..899e09dd659 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; }