From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 2836C385B539; Mon, 6 Mar 2023 10:26:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2836C385B539 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678098393; bh=gV1zCSSS/p+LkYCqgNmPS9UZjJf2mwebxBUmXdtOC58=; h=From:To:Subject:Date:From; b=bKb2r0X5PER59BeovMxWgCmYZfWIwRmM/e2oqqnF/BfUJy4I4S7Wx76PJ8BSzqspg Vf9iZSd/OG+AGhquTbjoMVLbmbvfzkr7nJDeRJ3gV9pP23Tor5mwxfyjC3dC2cLgaO XVWsgLuEGsZwCpHO3KhKyjSJoA3RVj2UQNWYi0nQ= 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 r13-6503] tree-optimization/109025 - fixup double reduction detection X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: b83acefb0409056b566133f66843ead6c04b8474 X-Git-Newrev: c1873079b05e399355eb79e4828ed9ba2d0c6968 Message-Id: <20230306102633.2836C385B539@sourceware.org> Date: Mon, 6 Mar 2023 10:26:33 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c1873079b05e399355eb79e4828ed9ba2d0c6968 commit r13-6503-gc1873079b05e399355eb79e4828ed9ba2d0c6968 Author: Richard Biener Date: Mon Mar 6 10:43:13 2023 +0100 tree-optimization/109025 - fixup double reduction detection The following closes a gap in double reduction detection where we in the outer loop analysis fail to verify the inner LC PHI use is the latch definition of the inner loop PHI. That latch definition is used to detect that an inner loop is part of a double reduction when later doing the inner loop analysis. PR tree-optimization/109025 * tree-vect-loop.cc (vect_is_simple_reduction): Verify the inner LC PHI use is the inner loop PHI latch definition before classifying an outer PHI as double reduction. * gcc.dg/vect/pr109025.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/vect/pr109025.c | 14 ++++++++++++++ gcc/tree-vect-loop.cc | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/vect/pr109025.c b/gcc/testsuite/gcc.dg/vect/pr109025.c new file mode 100644 index 00000000000..13fb0ce4ba9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr109025.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +int func_4(int t, int b) +{ + for (int tt1 = 0; tt1 < 128 ; tt1 ++) + { + for (int tt = 0; tt < 128; tt ++) + if (b) + t |= 3; + t |= 3; + } + return t; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index b17e8745d3f..320c15f144b 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -3894,6 +3894,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, return NULL; } + /* Verify there is an inner cycle composed of the PHI phi_use_stmt + and the latch definition op1. */ gimple *def1 = SSA_NAME_DEF_STMT (op1); if (gimple_bb (def1) && flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)) @@ -3901,7 +3903,9 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, && flow_bb_inside_loop_p (loop->inner, gimple_bb (def1)) && (is_gimple_assign (def1) || is_gimple_call (def1)) && is_a (phi_use_stmt) - && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt))) + && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt)) + && (op1 == PHI_ARG_DEF_FROM_EDGE (phi_use_stmt, + loop_latch_edge (loop->inner)))) { if (dump_enabled_p ()) report_vect_op (MSG_NOTE, def_stmt,