From 2ea6f4a377e51ed4d55cd8277f8c201ad66685f6 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 15 Jan 2021 10:08:58 +0100 Subject: [PATCH] tree-optimization/98685 - fix placement of extern converts Avoid advancing to the next stmt when inserting at region boundary and deal with a vector def being not the only child. 2021-01-15 Richard Biener PR tree-optimization/98685 * tree-vect-slp.c (vect_schedule_slp_node): Refactor handling of vector extern defs. * gcc.dg/vect/bb-slp-pr98685.c: New testcase. --- gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c | 15 +++++++++++++++ gcc/tree-vect-slp.c | 11 ++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c new file mode 100644 index 00000000000..b213335da78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr98685.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +char onelock_lock[16]; +void write(void); + +void lockit(int count) { + for (; count;) { + int pid, i; + char *p; + for (i = 0, p = (char *)&pid; i < sizeof 0; i++) + onelock_lock[i] = *p++; + write(); + } +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 6b6c9ccc0a0..1787ad74268 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -5915,6 +5915,7 @@ vect_schedule_slp_node (vec_info *vinfo, /* Emit other stmts after the children vectorized defs which is earliest possible. */ gimple *last_stmt = NULL; + bool seen_vector_def = false; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) if (SLP_TREE_DEF_TYPE (child) == vect_internal_def) { @@ -5966,8 +5967,7 @@ vect_schedule_slp_node (vec_info *vinfo, we do not insert before the region boundary. */ if (SLP_TREE_SCALAR_OPS (child).is_empty () && !vinfo->lookup_def (SLP_TREE_VEC_DEFS (child)[0])) - last_stmt = gsi_stmt (gsi_after_labels - (as_a (vinfo)->bbs[0])); + seen_vector_def = true; else { unsigned j; @@ -5987,7 +5987,12 @@ vect_schedule_slp_node (vec_info *vinfo, constants. */ if (!last_stmt) last_stmt = vect_find_first_scalar_stmt_in_slp (node)->stmt; - if (is_a (last_stmt)) + if (!last_stmt) + { + gcc_assert (seen_vector_def); + si = gsi_after_labels (as_a (vinfo)->bbs[0]); + } + else if (is_a (last_stmt)) si = gsi_after_labels (gimple_bb (last_stmt)); else { -- 2.30.2