aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-03-04 09:46:13 +0100
committerRichard Biener <rguenther@suse.de>2024-03-04 11:44:53 +0100
commit324d2907c86f05e40dc52d226940308f53a956c2 (patch)
tree1ac7be69bacd1da91d3a1e373d7070d3278c51c1
parentc27148f2f40654a638bcf429633be1c0561529d5 (diff)
downloadgcc-324d2907c86f05e40dc52d226940308f53a956c2.zip
gcc-324d2907c86f05e40dc52d226940308f53a956c2.tar.gz
gcc-324d2907c86f05e40dc52d226940308f53a956c2.tar.bz2
tree-optimization/114192 - scalar reduction kept live with early break vect
The following fixes a missing replacement of the reduction value used in the epilog, causing the scalar reduction to be kept live across the early break exit path. PR tree-optimization/114192 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Use the appropriate def for the live out stmt in case of an alternate exit.
-rw-r--r--gcc/tree-vect-loop.cc40
1 files changed, 26 insertions, 14 deletions
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 35f1f8c..761cdc6 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6066,20 +6066,32 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
stmt_vec_info single_live_out_stmt[] = { stmt_info };
array_slice<const stmt_vec_info> live_out_stmts = single_live_out_stmt;
- if (slp_reduc)
- /* All statements produce live-out values. */
- live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node);
- else if (slp_node)
- {
- /* The last statement in the reduction chain produces the live-out
- value. Note SLP optimization can shuffle scalar stmts to
- optimize permutations so we have to search for the last stmt. */
- for (k = 0; k < group_size; ++k)
- if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k]))
- {
- single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k];
- break;
- }
+ if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo)
+ && loop_exit != LOOP_VINFO_IV_EXIT (loop_vinfo)
+ /* ??? We should fend this off earlier. For conversions we create
+ multiple epilogues, one dead. */
+ && stmt_info == reduc_info->reduc_def)
+ {
+ gcc_assert (!slp_node);
+ single_live_out_stmt[0] = reduc_info;
+ }
+ else
+ {
+ if (slp_reduc)
+ /* All statements produce live-out values. */
+ live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node);
+ else if (slp_node)
+ {
+ /* The last statement in the reduction chain produces the live-out
+ value. Note SLP optimization can shuffle scalar stmts to
+ optimize permutations so we have to search for the last stmt. */
+ for (k = 0; k < group_size; ++k)
+ if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k]))
+ {
+ single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k];
+ break;
+ }
+ }
}
unsigned vec_num;