https://gcc.gnu.org/g:8af474aa5d5efdda7def6cdcec3f246df2c7026a
commit r15-4349-g8af474aa5d5efdda7def6cdcec3f246df2c7026a Author: Richard Biener <rguent...@suse.de> Date: Tue Oct 15 09:22:09 2024 +0200 tree-optimization/117147 - bogus re-use of previous ldst_p The following shows that in vect_build_slp_tree_1 we're eventually re-using the previous lane set ldst_p flag. Fixed by some refactoring. PR tree-optimization/117147 * tree-vect-slp.cc (vect_build_slp_tree_1): Put vars and initialization of per-lane data into the per-lane processing loop to avoid re-using previous lane state. Diff: --- gcc/tree-vect-slp.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 16332e0b6d74..8727246c27a6 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -1072,14 +1072,13 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, stmt_vec_info first_stmt_info = stmts[0]; code_helper first_stmt_code = ERROR_MARK; code_helper alt_stmt_code = ERROR_MARK; - code_helper rhs_code = ERROR_MARK; code_helper first_cond_code = ERROR_MARK; tree lhs; bool need_same_oprnds = false; - tree vectype = NULL_TREE, first_op1 = NULL_TREE; + tree first_op1 = NULL_TREE; stmt_vec_info first_load = NULL, prev_first_load = NULL; - bool first_stmt_ldst_p = false, ldst_p = false; - bool first_stmt_phi_p = false, phi_p = false; + bool first_stmt_ldst_p = false; + bool first_stmt_phi_p = false; int first_reduc_idx = -1; bool maybe_soft_fail = false; tree soft_fail_nunits_vectype = NULL_TREE; @@ -1088,6 +1087,10 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, stmt_vec_info stmt_info; FOR_EACH_VEC_ELT (stmts, i, stmt_info) { + bool ldst_p = false; + bool phi_p = false; + code_helper rhs_code = ERROR_MARK; + swap[i] = 0; matches[i] = false; if (!stmt_info) @@ -1139,7 +1142,7 @@ vect_build_slp_tree_1 (vec_info *vinfo, unsigned char *swap, return false; } - tree nunits_vectype; + tree vectype, nunits_vectype; if (!vect_get_vector_types_for_stmt (vinfo, stmt_info, &vectype, &nunits_vectype, group_size)) {