diff options
author | Richard Biener <rguenther@suse.de> | 2021-04-07 10:02:07 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2021-04-07 10:04:20 +0200 |
commit | d11bcbe166c03f722c0e0d41d6e87ac445758fba (patch) | |
tree | 23413b5a15b53a95a2811f0c43f328ead9f7545a | |
parent | 6eaf7ac6f49eae85825be185005338ca5c886161 (diff) | |
download | gcc-d11bcbe166c03f722c0e0d41d6e87ac445758fba.zip gcc-d11bcbe166c03f722c0e0d41d6e87ac445758fba.tar.gz gcc-d11bcbe166c03f722c0e0d41d6e87ac445758fba.tar.bz2 |
tree-optimization/99947 - avoid v.safe_push (v[0])
This avoids (again) the C++ pitfall of pushing a reference to
sth being reallocated.
2021-04-07 Richard Biener <rguenther@suse.de>
PR tree-optimization/99947
* tree-vect-loop.c (vectorizable_induction): Pre-allocate
steps vector to avoid pushing elements from the reallocated
vector.
* gcc.dg/torture/pr99947.c: New testcase.
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr99947.c | 18 | ||||
-rw-r--r-- | gcc/tree-vect-loop.c | 3 |
2 files changed, 20 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr99947.c b/gcc/testsuite/gcc.dg/torture/pr99947.c new file mode 100644 index 0000000..2cf3ec6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr99947.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ + +int a, b, d, e; +short c; +void f() { + for (; e; e++) { + int g = 6; + for (; g > 2; g--) { + int i = -8; + while (i < 20) { + i += 5; + a += b; + } + c *= d; + } + b--; + } +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 4e928c6..93fa292 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -8202,11 +8202,12 @@ vectorizable_induction (loop_vec_info loop_vinfo, /* Fill up to the number of vectors we need for the whole group. */ nivs = least_common_multiple (group_size, const_nunits) / const_nunits; + vec_steps.reserve (nivs-ivn); for (; ivn < nivs; ++ivn) { SLP_TREE_VEC_STMTS (slp_node) .quick_push (SLP_TREE_VEC_STMTS (slp_node)[0]); - vec_steps.safe_push (vec_steps[0]); + vec_steps.quick_push (vec_steps[0]); } } |