diff options
author | Richard Biener <rguenther@suse.de> | 2020-11-02 09:38:09 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2020-11-02 11:03:30 +0100 |
commit | 5b41d673ad96dd2f9a7dec3877d0381320ccadb1 (patch) | |
tree | 0c1ea5efd59af78cca22b7de87c715927874f7dd /gcc/tree-vect-loop.c | |
parent | a159081ad4259c42456bd3dc2b637747c373c5a5 (diff) | |
download | gcc-5b41d673ad96dd2f9a7dec3877d0381320ccadb1.zip gcc-5b41d673ad96dd2f9a7dec3877d0381320ccadb1.tar.gz gcc-5b41d673ad96dd2f9a7dec3877d0381320ccadb1.tar.bz2 |
tree-optimization/97558 - avoid SLP analyzing irrelevant stmts
This avoids analyzing reductions that are not relevant (thus dead)
which eventually will lead into crashes because the participating
stmts meta is not analyzed. For this to work the patch also
properly removes reduction groups that are not uniformly recognized
as patterns.
2020-11-02 Richard Biener <rguenther@suse.de>
PR tree-optimization/97558
* tree-vect-loop.c (vect_fixup_scalar_cycles_with_patterns):
Check for any mismatch in pattern vs. non-pattern and dissolve
the group if there is one.
* tree-vect-slp.c (vect_analyze_slp_instance): Avoid
analyzing not relevant reductions.
(vect_analyze_slp): Avoid analyzing not relevant reduction
groups.
* gcc.dg/vect/pr97558.c: New testcase.
Diffstat (limited to 'gcc/tree-vect-loop.c')
-rw-r--r-- | gcc/tree-vect-loop.c | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 5ab125d..353703c 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -666,27 +666,50 @@ vect_fixup_scalar_cycles_with_patterns (loop_vec_info loop_vinfo) unsigned i; FOR_EACH_VEC_ELT (LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo), i, first) - if (STMT_VINFO_IN_PATTERN_P (first)) - { - stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (first); - while (next) - { - if (! STMT_VINFO_IN_PATTERN_P (next) - || STMT_VINFO_REDUC_IDX (STMT_VINFO_RELATED_STMT (next)) == -1) - break; - next = REDUC_GROUP_NEXT_ELEMENT (next); - } - /* If not all stmt in the chain are patterns or if we failed - to update STMT_VINFO_REDUC_IDX try to handle the chain - without patterns. */ - if (! next - && STMT_VINFO_REDUC_IDX (STMT_VINFO_RELATED_STMT (first)) != -1) - { - vect_fixup_reduc_chain (first); - LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo)[i] - = STMT_VINFO_RELATED_STMT (first); - } - } + { + stmt_vec_info next = REDUC_GROUP_NEXT_ELEMENT (first); + while (next) + { + if ((STMT_VINFO_IN_PATTERN_P (next) + != STMT_VINFO_IN_PATTERN_P (first)) + || STMT_VINFO_REDUC_IDX (vect_stmt_to_vectorize (next)) == -1) + break; + next = REDUC_GROUP_NEXT_ELEMENT (next); + } + /* If all reduction chain members are well-formed patterns adjust + the group to group the pattern stmts instead. */ + if (! next + && STMT_VINFO_REDUC_IDX (vect_stmt_to_vectorize (first)) != -1) + { + if (STMT_VINFO_IN_PATTERN_P (first)) + { + vect_fixup_reduc_chain (first); + LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo)[i] + = STMT_VINFO_RELATED_STMT (first); + } + } + /* If not all stmt in the chain are patterns or if we failed + to update STMT_VINFO_REDUC_IDX dissolve the chain and handle + it as regular reduction instead. */ + else + { + stmt_vec_info vinfo = first; + stmt_vec_info last = NULL; + while (vinfo) + { + next = REDUC_GROUP_NEXT_ELEMENT (vinfo); + REDUC_GROUP_FIRST_ELEMENT (vinfo) = NULL; + REDUC_GROUP_NEXT_ELEMENT (vinfo) = NULL; + last = vinfo; + vinfo = next; + } + STMT_VINFO_DEF_TYPE (vect_stmt_to_vectorize (first)) + = vect_internal_def; + loop_vinfo->reductions.safe_push (vect_stmt_to_vectorize (last)); + LOOP_VINFO_REDUCTION_CHAINS (loop_vinfo).unordered_remove (i); + --i; + } + } } /* Function vect_get_loop_niters. |