Commit f7dff769 by Andre Vieira

PR tree-optimization/92429 do not fold when updating epilogue statements

This patch addresses the problem reported in PR92429.  When creating an
epilogue for vectorization we have to replace the SSA_NAMEs in the
PATTERN_DEF_SEQs and RELATED_STMTs of the epilogue's loop_vec_infos. When doing
this we were using simplify_replace_tree which always folds the replacement.
This may lead to a different tree-node than the one which was analyzed in
vect_loop_analyze.  In turn the new tree-node may require a different
vectorization than the one we had prepared for which caused the ICE in
question.

gcc/ChangeLog:
2020-01-16  Andre Vieira  <andre.simoesdiasvieira@arm.com>

	PR tree-optimization/92429
	* tree-ssa-loop-niter.h (simplify_replace_tree): Add parameter.
	* tree-ssa-loop-niter.c (simplify_replace_tree): Add parameter to
	control folding.
	* tree-vect-loop.c (update_epilogue_vinfo): Do not fold when replacing
	tree.

gcc/testsuite/ChangeLog:
2020-01-16  Andre Vieira  <andre.simoesdiasvieira@arm.com>

	PR tree-optimization/92429
	* gcc.dg/vect/pr92429.c: New test.
parent 3b5757ea
2020-01-16 Andre Vieira <andre.simoesdiasvieira@arm.com>
PR tree-optimization/92429
* tree-ssa-loop-niter.h (simplify_replace_tree): Add parameter.
* tree-ssa-loop-niter.c (simplify_replace_tree): Add parameter to
control folding.
* tree-vect-loop.c (update_epilogue_vinfo): Do not fold when replacing
tree.
2020-01-16 Richard Sandiford <richard.sandiford@arm.com> 2020-01-16 Richard Sandiford <richard.sandiford@arm.com>
* config/aarch64/aarch64.c (aarch64_split_sve_subreg_move): Apply * config/aarch64/aarch64.c (aarch64_split_sve_subreg_move): Apply
......
2020-01-16 Andre Vieira <andre.simoesdiasvieira@arm.com>
PR tree-optimization/92429
* gcc.dg/vect/pr92429.c: New test.
2020-01-16 Tobias Burnus <tobias@codesourcery.com> 2020-01-16 Tobias Burnus <tobias@codesourcery.com>
PR fortran/93253 PR fortran/93253
......
...@@ -1934,7 +1934,8 @@ number_of_iterations_cond (class loop *loop, ...@@ -1934,7 +1934,8 @@ number_of_iterations_cond (class loop *loop,
tree tree
simplify_replace_tree (tree expr, tree old, tree new_tree, simplify_replace_tree (tree expr, tree old, tree new_tree,
tree (*valueize) (tree, void*), void *context) tree (*valueize) (tree, void*), void *context,
bool do_fold)
{ {
unsigned i, n; unsigned i, n;
tree ret = NULL_TREE, e, se; tree ret = NULL_TREE, e, se;
...@@ -1966,7 +1967,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree, ...@@ -1966,7 +1967,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree,
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
e = TREE_OPERAND (expr, i); e = TREE_OPERAND (expr, i);
se = simplify_replace_tree (e, old, new_tree, valueize, context); se = simplify_replace_tree (e, old, new_tree, valueize, context, do_fold);
if (e == se) if (e == se)
continue; continue;
...@@ -1976,7 +1977,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree, ...@@ -1976,7 +1977,7 @@ simplify_replace_tree (tree expr, tree old, tree new_tree,
TREE_OPERAND (ret, i) = se; TREE_OPERAND (ret, i) = se;
} }
return (ret ? fold (ret) : expr); return (ret ? (do_fold ? fold (ret) : ret) : expr);
} }
/* Expand definitions of ssa names in EXPR as long as they are simple /* Expand definitions of ssa names in EXPR as long as they are simple
......
...@@ -58,7 +58,7 @@ extern void free_numbers_of_iterations_estimates (class loop *); ...@@ -58,7 +58,7 @@ extern void free_numbers_of_iterations_estimates (class loop *);
extern void free_numbers_of_iterations_estimates (function *); extern void free_numbers_of_iterations_estimates (function *);
extern tree simplify_replace_tree (tree, tree, extern tree simplify_replace_tree (tree, tree,
tree, tree (*)(tree, void *) = NULL, tree, tree (*)(tree, void *) = NULL,
void * = NULL); void * = NULL, bool do_fold = true);
extern void substitute_in_loop_info (class loop *, tree, tree); extern void substitute_in_loop_info (class loop *, tree, tree);
#endif /* GCC_TREE_SSA_LOOP_NITER_H */ #endif /* GCC_TREE_SSA_LOOP_NITER_H */
...@@ -8434,8 +8434,13 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree advance) ...@@ -8434,8 +8434,13 @@ update_epilogue_loop_vinfo (class loop *epilogue, tree advance)
gimple_set_op (stmt, j, *new_op); gimple_set_op (stmt, j, *new_op);
else else
{ {
/* PR92429: The last argument of simplify_replace_tree disables
folding when replacing arguments. This is required as
otherwise you might end up with different statements than the
ones analyzed in vect_loop_analyze, leading to different
vectorization. */
op = simplify_replace_tree (op, NULL_TREE, NULL_TREE, op = simplify_replace_tree (op, NULL_TREE, NULL_TREE,
&find_in_mapping, &mapping); &find_in_mapping, &mapping, false);
gimple_set_op (stmt, j, op); gimple_set_op (stmt, j, op);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment