From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 816F9389902D; Fri, 16 Jul 2021 07:41:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 816F9389902D 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-2347] tree-optimization/101462 - fix signedness of reused reduction vector X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: a314d50336db752f2ae2c50262956ce4490567ac X-Git-Newrev: d6aa28bb93c6fc9042ee87ff7addac60647dbddb Message-Id: <20210716074149.816F9389902D@sourceware.org> Date: Fri, 16 Jul 2021 07:41:49 +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: Fri, 16 Jul 2021 07:41:49 -0000 https://gcc.gnu.org/g:d6aa28bb93c6fc9042ee87ff7addac60647dbddb commit r12-2347-gd6aa28bb93c6fc9042ee87ff7addac60647dbddb Author: Richard Biener Date: Fri Jul 16 08:50:40 2021 +0200 tree-optimization/101462 - fix signedness of reused reduction vector This fixes the partial reduction of the reused reduction vector to carried out in the correct sign and the correctly signed vector recorded for the skip edge use. 2021-07-16 Richard Biener * tree-vect-loop.c (vect_transform_cycle_phi): Correct sign conversion issues with the partial reduction of the reused vector accumulator. Diff: --- gcc/tree-vect-loop.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index fc3dab0d143..00a57b2ba62 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -7706,21 +7706,35 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo, if (auto *accumulator = reduc_info->reused_accumulator) { tree def = accumulator->reduc_input; - unsigned int nreduc; - bool res = constant_multiple_p (TYPE_VECTOR_SUBPARTS (TREE_TYPE (def)), - TYPE_VECTOR_SUBPARTS (vectype_out), - &nreduc); - gcc_assert (res); - if (nreduc != 1) - { - /* Reduce the single vector to a smaller one. */ + if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def))) + { + unsigned int nreduc; + bool res = constant_multiple_p (TYPE_VECTOR_SUBPARTS + (TREE_TYPE (def)), + TYPE_VECTOR_SUBPARTS (vectype_out), + &nreduc); + gcc_assert (res); gimple_seq stmts = NULL; - def = vect_create_partial_epilog (def, vectype_out, - STMT_VINFO_REDUC_CODE (reduc_info), - &stmts); + /* Reduce the single vector to a smaller one. */ + if (nreduc != 1) + { + /* Perform the reduction in the appropriate type. */ + tree rvectype = vectype_out; + if (!useless_type_conversion_p (TREE_TYPE (vectype_out), + TREE_TYPE (TREE_TYPE (def)))) + rvectype = build_vector_type (TREE_TYPE (TREE_TYPE (def)), + TYPE_VECTOR_SUBPARTS + (vectype_out)); + def = vect_create_partial_epilog (def, rvectype, + STMT_VINFO_REDUC_CODE + (reduc_info), + &stmts); + } /* Adjust the input so we pick up the partially reduced value for the skip edge in vect_create_epilog_for_reduction. */ accumulator->reduc_input = def; + if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def))) + def = gimple_convert (&stmts, vectype_out, def); if (loop_vinfo->main_loop_edge) { /* While we'd like to insert on the edge this will split