From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 462523858423; Mon, 6 Dec 2021 11:53:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 462523858423 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5803] tree-optimization/103544 - SLP reduction chain as SLP reduction issue X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 4dc6d19222581c77a174d44d97507d234fb7e39b X-Git-Newrev: ee01694151edc7e8aef84dc3c484469e2ae443a0 Message-Id: <20211206115358.462523858423@sourceware.org> Date: Mon, 6 Dec 2021 11:53:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Dec 2021 11:53:58 -0000 https://gcc.gnu.org/g:ee01694151edc7e8aef84dc3c484469e2ae443a0 commit r12-5803-gee01694151edc7e8aef84dc3c484469e2ae443a0 Author: Richard Biener Date: Mon Dec 6 11:43:28 2021 +0100 tree-optimization/103544 - SLP reduction chain as SLP reduction issue When SLP reduction chain vectorization support added handling of an outer conversion in the chain picking a failed reduction up as SLP reduction that broke the invariant that the whole reduction was forward reachable. The following plugs that hole noting a future enhancement possibility. 2021-12-06 Richard Biener PR tree-optimization/103544 * tree-vect-slp.c (vect_analyze_slp): Only add a SLP reduction opportunity if the stmt in question is the reduction root. (dot_slp_tree): Add missing check for NULL child. * gcc.dg/vect/pr103544.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr103544.c | 24 ++++++++++++++++++++++++ gcc/tree-vect-slp.c | 12 +++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr103544.c b/gcc/testsuite/gcc.dg/vect/pr103544.c new file mode 100644 index 00000000000..c8bdee86e77 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr103544.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ +/* { dg-additional-options "-march=haswell" { target x86_64-*-* i?86-*-* } } */ + +int crash_me(char* ptr, unsigned long size) +{ + short result[16] = {0}; + + unsigned long no_iters = 0; + for(unsigned long i = 0; i < size - 12; i+= 13){ + for(unsigned long j = 0; j < 12; j++){ + result[j] += ptr[i + j] - '0'; + } + no_iters++; + } + + int result_int = 0; + for(int j = 0; j < 12; j++){ + int bit_value = result[j] > no_iters/2 ? 1 : 0; + result_int |= bit_value; + } + + return result_int; +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index bc22ffeed82..b912c3577df 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -2537,7 +2537,8 @@ dot_slp_tree (FILE *f, slp_tree node, hash_set &visited) fprintf (f, "\"%p\" -> \"%p\";", (void *)node, (void *)child); for (slp_tree child : SLP_TREE_CHILDREN (node)) - dot_slp_tree (f, child, visited); + if (child) + dot_slp_tree (f, child, visited); } DEBUG_FUNCTION void @@ -3418,8 +3419,13 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size) vinfo = next; } STMT_VINFO_DEF_TYPE (first_element) = vect_internal_def; - /* It can be still vectorized as part of an SLP reduction. */ - loop_vinfo->reductions.safe_push (last); + /* It can be still vectorized as part of an SLP reduction. + ??? But only if we didn't skip a conversion around the group. + In that case we'd have to reverse engineer that conversion + stmt following the chain using reduc_idx and from the PHI + using reduc_def. */ + if (STMT_VINFO_DEF_TYPE (last) == vect_reduction_def) + loop_vinfo->reductions.safe_push (last); } /* Find SLP sequences starting from groups of reductions. */