This properly handles reduction PHI nodes with unrepresented initial value as leaf in the SLP graph.
Bootstrap & regtest running on x86_64-unknown-linux-gnu. 2020-11-16 Richard Biener <rguent...@suse.de> PR tree-optimization/97838 * tree-vect-slp.c (vect_slp_build_vertices): Properly handle a NULL child as leaf. * gcc.dg/vect/pr97838.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr97838.c | 11 +++++++++++ gcc/tree-vect-slp.c | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr97838.c diff --git a/gcc/testsuite/gcc.dg/vect/pr97838.c b/gcc/testsuite/gcc.dg/vect/pr97838.c new file mode 100644 index 00000000000..06ec0358f6e --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr97838.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ + +int a, b, c, d; + +void f() { + while (c++) { + int e = -1; + d = a ? e / a : e; + b ^= ~d; + } +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index e4c2aa480e5..0fb463f4bd0 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -2609,13 +2609,18 @@ vect_slp_build_vertices (hash_set<slp_tree> &visited, slp_tree node, vertices.safe_push (node); bool leaf = true; + bool force_leaf = false; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (child) { leaf = false; vect_slp_build_vertices (visited, child, vertices, leafs); } - if (leaf) + else + /* A NULL SLP_TREE_CHILDREN entry is a not represented initial + value of reductions which means the reduction itself is leaf. */ + force_leaf = true; + if (leaf || force_leaf) leafs.safe_push (node->vertex); } -- 2.26.2