aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-01-19 13:55:09 +0100
committerRichard Biener <rguenther@suse.de>2024-01-22 08:48:26 +0100
commit86f3cbdaa6f60eaff1cdb4ab2f1a9bc796b67207 (patch)
tree702e743b95c9c643df4c16dd2f735212b648c736 /gcc/tree-vect-loop.cc
parenta618b3c65745a6992ced4df60c186241c2da6eae (diff)
downloadgcc-86f3cbdaa6f60eaff1cdb4ab2f1a9bc796b67207.zip
gcc-86f3cbdaa6f60eaff1cdb4ab2f1a9bc796b67207.tar.gz
gcc-86f3cbdaa6f60eaff1cdb4ab2f1a9bc796b67207.tar.bz2
tree-optimization/113373 - add missing LC PHIs for live operations
The following makes reduction epilogue code generation happy by properly adding LC PHIs to the exit blocks for multiple exit vectorized loops. Some refactoring might make the flow easier to follow but I've refrained from doing that with this patch. I've kept some fixes in reduction epilogue generation from the earlier attempt fixing this PR. PR tree-optimization/113373 * tree-vect-loop-manip.cc (slpeel_tree_duplicate_loop_to_edge_cfg): Create LC PHIs in the exit blocks where necessary. * tree-vect-loop.cc (vectorizable_live_operation): Do not try to handle missing LC PHIs. (find_connected_edge): Remove. (vect_create_epilog_for_reduction): Cleanup use of auto_vec. * gcc.dg/vect/vect-early-break_104-pr113373.c: New testcase.
Diffstat (limited to 'gcc/tree-vect-loop.cc')
-rw-r--r--gcc/tree-vect-loop.cc46
1 files changed, 12 insertions, 34 deletions
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 4769d6f..fe63125 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6017,7 +6017,6 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
int j, i;
vec<tree> &scalar_results = reduc_info->reduc_scalar_results;
unsigned int group_size = 1, k;
- auto_vec<gimple *> phis;
/* SLP reduction without reduction chain, e.g.,
# a1 = phi <a2, a0>
# b1 = phi <b2, b0>
@@ -6930,12 +6929,12 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
use <s_out4> */
gcc_assert (live_out_stmts.size () == scalar_results.length ());
+ auto_vec<gimple *> phis;
for (k = 0; k < live_out_stmts.size (); k++)
{
stmt_vec_info scalar_stmt_info = vect_orig_stmt (live_out_stmts[k]);
scalar_dest = gimple_get_lhs (scalar_stmt_info->stmt);
- phis.create (3);
/* Find the loop-closed-use at the loop exit of the original scalar
result. (The reduction result is expected to have two immediate uses,
one at the latch block, and one at the loop exit). For double
@@ -6988,7 +6987,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
}
}
- phis.release ();
+ phis.truncate (0);
}
}
@@ -10710,18 +10709,6 @@ vectorizable_live_operation_1 (loop_vec_info loop_vinfo,
return new_tree;
}
-/* Find the edge that's the final one in the path from SRC to DEST and
- return it. This edge must exist in at most one forwarder edge between. */
-
-static edge
-find_connected_edge (edge src, basic_block dest)
-{
- if (src->dest == dest)
- return src;
-
- return find_edge (src->dest, dest);
-}
-
/* Function vectorizable_live_operation.
STMT_INFO computes a value that is used outside the loop. Check if
@@ -10964,13 +10951,8 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
{
edge e = gimple_phi_arg_edge (as_a <gphi *> (use_stmt),
phi_arg_index_from_use (use_p));
- bool main_exit_edge = e == main_e
- || find_connected_edge (main_e, e->src);
-
- /* Early exits have an merge block, we want the merge block itself
- so use ->src. For main exit the merge block is the
- destination. */
- basic_block dest = main_exit_edge ? main_e->dest : e->src;
+ gcc_assert (loop_exit_edge_p (loop, e));
+ bool main_exit_edge = e == main_e;
tree tmp_vec_lhs = vec_lhs;
tree tmp_bitstart = bitstart;
@@ -10988,22 +10970,18 @@ vectorizable_live_operation (vec_info *vinfo, stmt_vec_info stmt_info,
gimple_stmt_iterator exit_gsi;
tree new_tree
= vectorizable_live_operation_1 (loop_vinfo, stmt_info,
- dest, vectype, ncopies,
+ e->dest, vectype, ncopies,
slp_node, bitsize,
tmp_bitstart, tmp_vec_lhs,
lhs_type, &exit_gsi);
- if (gimple_phi_num_args (use_stmt) == 1)
- {
- auto gsi = gsi_for_stmt (use_stmt);
- remove_phi_node (&gsi, false);
- tree lhs_phi = gimple_phi_result (use_stmt);
- gimple *copy = gimple_build_assign (lhs_phi, new_tree);
- gsi_insert_before (&exit_gsi, copy, GSI_SAME_STMT);
- }
- else
- SET_PHI_ARG_DEF (use_stmt, e->dest_idx, new_tree);
- }
+ auto gsi = gsi_for_stmt (use_stmt);
+ remove_phi_node (&gsi, false);
+ tree lhs_phi = gimple_phi_result (use_stmt);
+ gimple *copy = gimple_build_assign (lhs_phi, new_tree);
+ gsi_insert_before (&exit_gsi, copy, GSI_SAME_STMT);
+ break;
+ }
/* There a no further out-of-loop uses of lhs by LC-SSA construction. */
FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, lhs)