From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 1540B3858D37; Thu, 22 Feb 2024 12:14:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1540B3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708604052; bh=YpmG6KWouU2QJHLt+lezNoFR7MBSLdOmAAwSU61Tvoo=; h=From:To:Subject:Date:From; b=LJQ+4pX247jP/xGbs0DrgUJ/3mauadvEeYoadrb/8Ujxe7a4m74g6Nay6knTQCqx/ 7v1BiJh2Aq1olewFJllxCzDbi4MFzHQ2DeV7ZCZ1NFP14dSIJvo/bWiw0W2uKTNMCT aDOqe3YZQB4wAAsmINDmlogwfY9NZrpu7m/UgDFU= 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 r14-9134] tree-optimization/114027 - conditional reduction chain X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: a0782531b8270f0fdb3f3e09b4ce544d5d1eef14 X-Git-Newrev: 549f251f055e3a0b0084189a3012c4f15d635e75 Message-Id: <20240222121412.1540B3858D37@sourceware.org> Date: Thu, 22 Feb 2024 12:14:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:549f251f055e3a0b0084189a3012c4f15d635e75 commit r14-9134-g549f251f055e3a0b0084189a3012c4f15d635e75 Author: Richard Biener Date: Thu Feb 22 10:50:12 2024 +0100 tree-optimization/114027 - conditional reduction chain When we classify a conditional reduction chain as CONST_COND_REDUCTION we fail to verify all involved conditionals have the same constant. That's a quite unlikely situation so the following simply disables such classification when there's more than one reduction statement. PR tree-optimization/114027 * tree-vect-loop.cc (vecctorizable_reduction): Use optimized condition reduction classification only for single-element chains. * gcc.dg/vect/pr114027.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr114027.c | 26 ++++++++++++++++++++++++++ gcc/tree-vect-loop.cc | 11 ++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr114027.c b/gcc/testsuite/gcc.dg/vect/pr114027.c new file mode 100644 index 000000000000..ead9cdd982d7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr114027.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +int __attribute__((noipa)) +foo (int *f, int n) +{ + int res = 0; + for (int i = 0; i < n; ++i) + { + if (f[2*i]) + res = 2; + if (f[2*i+1]) + res = -2; + } + return res; +} + +int f[] = { 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0 }; + +int +main () +{ + if (foo (f, 16) != 2) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 5a5865c42fc6..35f1f8c7d424 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7759,17 +7759,18 @@ vectorizable_reduction (loop_vec_info loop_vinfo, < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (vectype_op[i])))))) vectype_in = vectype_op[i]; - if (op.code == COND_EXPR) + /* Record how the non-reduction-def value of COND_EXPR is defined. + ??? For a chain of multiple CONDs we'd have to match them up all. */ + if (op.code == COND_EXPR && reduc_chain_length == 1) { - /* Record how the non-reduction-def value of COND_EXPR is defined. */ if (dt == vect_constant_def) { cond_reduc_dt = dt; cond_reduc_val = op.ops[i]; } - if (dt == vect_induction_def - && def_stmt_info - && is_nonwrapping_integer_induction (def_stmt_info, loop)) + else if (dt == vect_induction_def + && def_stmt_info + && is_nonwrapping_integer_induction (def_stmt_info, loop)) { cond_reduc_dt = dt; cond_stmt_vinfo = def_stmt_info;