From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 7DF1F3857361; Mon, 17 Oct 2022 13:10:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7DF1F3857361 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666012249; bh=l9O7Fittpx6DDf6iFQOfPKkUw44lHBDgNdXvUahsC1U=; h=From:To:Subject:Date:From; b=Kia8iBooZB9sJyuxgXfrCn7cQL2eEFSgwgz35WeM+ZKMXeQcLp1zUEVjOWtNm05Fy K+xhD5eozcTgRnUNeFnBfVcCu2TkW9XVk50bd0S40DahTY/PGyMt0c5jLdyjoM6PZJ M4rUxRUPBaICZRDbxbkHt9qyqTRLLmabufFbMZds= 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-8839] tree-optimization/107160 - avoid reusing multiple accumulators X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: ff0a274e5c3026b105c7f51126fa51f8178fa42c X-Git-Newrev: d282dd56275485a88e1fe9c4ae1939b62d23b20b Message-Id: <20221017131049.7DF1F3857361@sourceware.org> Date: Mon, 17 Oct 2022 13:10:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d282dd56275485a88e1fe9c4ae1939b62d23b20b commit r12-8839-gd282dd56275485a88e1fe9c4ae1939b62d23b20b Author: Richard Biener Date: Thu Oct 13 14:24:05 2022 +0200 tree-optimization/107160 - avoid reusing multiple accumulators Epilogue vectorization is not set up to re-use a vectorized accumulator consisting of more than one vector. For non-SLP we always reduce to a single but for SLP that isn't happening. In such case we currenlty miscompile the epilog so avoid this. PR tree-optimization/107160 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Do not register accumulator if we failed to reduce it to a single vector. * gcc.dg/vect/pr107160.c: New testcase. (cherry picked from commit 5cbaf84c191b9a3e3cb26545c808d208bdbf2ab5) Diff: --- gcc/testsuite/gcc.dg/vect/pr107160.c | 41 ++++++++++++++++++++++++++++++++++++ gcc/tree-vect-loop.cc | 3 ++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr107160.c b/gcc/testsuite/gcc.dg/vect/pr107160.c new file mode 100644 index 00000000000..4f9f853cafb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107160.c @@ -0,0 +1,41 @@ +/* { dg-do run } */ + +#include + +#define N 128 +float fl[N]; + +__attribute__ ((noipa)) void +init () +{ + for (int i = 0; i < N; i++) + fl[i] = i; +} + +__attribute__ ((noipa)) float +foo (int n1) +{ + float sum0, sum1, sum2, sum3; + sum0 = sum1 = sum2 = sum3 = 0.0f; + + int n = (n1 / 4) * 4; + for (int i = 0; i < n; i += 4) + { + sum0 += fabs (fl[i]); + sum1 += fabs (fl[i + 1]); + sum2 += fabs (fl[i + 2]); + sum3 += fabs (fl[i + 3]); + } + + return sum0 + sum1 + sum2 + sum3; +} + +int +main () +{ + init (); + float res = foo (80); + if (res != 3160) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index d1c19ce23fa..442679836ee 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6083,7 +6083,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, } /* Record this operation if it could be reused by the epilogue loop. */ - if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION) + if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION + && vec_num == 1) loop_vinfo->reusable_accumulators.put (scalar_results[0], { orig_reduc_input, reduc_info });