From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 223B23858D38; Wed, 24 Jan 2024 07:37:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 223B23858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706081861; bh=VCSdGSrkvhaqd/+y5NhRxhS1H6W7s1sIgnSFHHVwul0=; h=From:To:Subject:Date:From; b=RaW/z66lw1eoJLwQX4n7u4bmNFjIgnR46pF6sbXoQj+L87aA8E6C55BQW+IrspE7m wroe4IuhANA6EZzQmSxCjO/3GWuLaX5TifjdjDNLHNzxjmfA5iWkQN+MB0f3tV/hJu dFtWagVVGR6eqHqViPHoMAccb7TaeGL3XjTeqwyA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Tamar Christina To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8382] middle-end: fix epilog reductions when vector iters peeled [PR113364] X-Act-Checkin: gcc X-Git-Author: Tamar Christina X-Git-Refname: refs/heads/master X-Git-Oldrev: d89537a1417954fad40a5c97590fbc61e6400796 X-Git-Newrev: 72429448fd16733f876b282bb37a0653049c446d Message-Id: <20240124073741.223B23858D38@sourceware.org> Date: Wed, 24 Jan 2024 07:37:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:72429448fd16733f876b282bb37a0653049c446d commit r14-8382-g72429448fd16733f876b282bb37a0653049c446d Author: Tamar Christina Date: Wed Jan 24 07:37:17 2024 +0000 middle-end: fix epilog reductions when vector iters peeled [PR113364] This fixes a bug where vect_create_epilog_for_reduction does not handle the case where all exits are early exits. In this case we should do like induction handling code does and not have a main exit. This shows that some new miscompiles are happening (stage3 is likely miscompiled) but that's unrelated to this patch and I'll look at it next. gcc/ChangeLog: PR tree-optimization/113364 * tree-vect-loop.cc (vect_create_epilog_for_reduction): If all exits all early exits then we must reduce from the first offset for all of them. gcc/testsuite/ChangeLog: PR tree-optimization/113364 * gcc.dg/vect/vect-early-break_107-pr113364.c: New test. Diff: --- .../gcc.dg/vect/vect-early-break_107-pr113364.c | 22 ++++++++++++++++++++++ gcc/tree-vect-loop.cc | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c new file mode 100644 index 00000000000..f489265dbfe --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-early-break_107-pr113364.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-add-options vect_early_break } */ +/* { dg-require-effective-target vect_early_break } */ +/* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-w" } */ + +typedef const unsigned char *It; +It DecodeSLEB128(It begin, It end, int *v) { + int value = 0; + unsigned shift = 0; + unsigned char byte; + do + { + if (begin == end) + return begin; + byte = *(begin++); + int slice = byte & 0x7f; + value |= slice << shift; + } while (byte >= 128); + *v = value; + return begin; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index fe631252dc2..4da1421c8f0 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -5982,7 +5982,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, loop-closed PHI of the inner loop which we remember as def for the reduction PHI generation. */ bool double_reduc = false; - bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit; + bool main_exit_p = LOOP_VINFO_IV_EXIT (loop_vinfo) == loop_exit + && !LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo); stmt_vec_info rdef_info = stmt_info; if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_double_reduction_def) {