From patchwork Thu Jan 23 14:02:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1228019 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518138-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=An2osj5w; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 483PB34Qb3z9sP3 for ; Fri, 24 Jan 2020 01:03:06 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=iu+Rb2zfq+Oc2FwSRKN0Crw/UJ0J5uOVEHQwxH9LGmmKUNgzNXDya NP75OVkc3NlnHmiM0OyzgKlynLcEN+/1nY9l2JQbKa+lbFPD0k7OKdkcaKf3VKYt UcylKKBejbGRFaPLCX6ssYdje+zFfAeOc+cF0nVF5/9AbMvPsditDE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ec+wDyOObmT5CAwm2cttj42BUGk=; b=An2osj5w9y/Eo8iaV0x1 zdK1dLZnYNTi5my6K0qEsRld3npdp3z0JavcP+/pw5NUVmmBjBlfJB1m+shzMpmO PlCnRobsMNviFiZP1GVk/MyUhph/qK2++dqml8A1gCa5xRqr7KM42n8xisJyeiE4 qmbxRUrHG1RLmReiPukJfz0= Received: (qmail 29775 invoked by alias); 23 Jan 2020 14:02:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 29768 invoked by uid 89); 23 Jan 2020 14:02:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=dr, HX-Languages-Length:4062, Delay X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 14:02:56 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1537DB1BA for ; Thu, 23 Jan 2020 14:02:54 +0000 (UTC) Date: Thu, 23 Jan 2020 15:02:54 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/93397 delay converted reduction chain adjustment Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 The following delays adjusting the SLP graph for converted reduction chains to a point where the SLP build no longer can fail since we otherwise fail to undo marking the conversion as a group. Bootstrap & regtest running on x86_64-unknown-linux-gnu. Richard. 2020-01-23 Richard Biener PR tree-optimization/93397 * tree-vect-slp.c (vect_analyze_slp_instance): Delay converted reduction chain SLP graph adjustment. * gcc.dg/torture/pr93397.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr93397.c | 14 ++++++++ gcc/tree-vect-slp.c | 58 ++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr93397.c diff --git a/gcc/testsuite/gcc.dg/torture/pr93397.c b/gcc/testsuite/gcc.dg/torture/pr93397.c new file mode 100644 index 00000000000..c19b7983e58 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr93397.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-ftree-vectorize" } */ + +char +bn (char *vu) +{ + int b6; + char wv = 0; + + for (b6 = 0; b6 <= 64; b6 += 4) + wv += vu[b6] + vu[b6 + 1]; + + return wv; +} diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index cebaa811dd2..b13beeb3689 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -2210,34 +2210,6 @@ vect_analyze_slp_instance (vec_info *vinfo, &tree_size, bst_map); if (node != NULL) { - /* If this is a reduction chain with a conversion in front - amend the SLP tree with a node for that. */ - if (!dr - && REDUC_GROUP_FIRST_ELEMENT (stmt_info) - && STMT_VINFO_DEF_TYPE (stmt_info) != vect_reduction_def) - { - /* Get at the conversion stmt - we know it's the single use - of the last stmt of the reduction chain. */ - gimple *tem = vect_orig_stmt (scalar_stmts[group_size - 1])->stmt; - use_operand_p use_p; - gimple *use_stmt; - bool r = single_imm_use (gimple_assign_lhs (tem), &use_p, &use_stmt); - gcc_assert (r); - next_info = vinfo->lookup_stmt (use_stmt); - next_info = vect_stmt_to_vectorize (next_info); - scalar_stmts = vNULL; - scalar_stmts.create (group_size); - for (unsigned i = 0; i < group_size; ++i) - scalar_stmts.quick_push (next_info); - slp_tree conv = vect_create_new_slp_node (scalar_stmts); - SLP_TREE_CHILDREN (conv).quick_push (node); - node = conv; - /* We also have to fake this conversion stmt as SLP reduction group - so we don't have to mess with too much code elsewhere. */ - REDUC_GROUP_FIRST_ELEMENT (next_info) = next_info; - REDUC_GROUP_NEXT_ELEMENT (next_info) = NULL; - } - /* Calculate the unrolling factor based on the smallest type. */ poly_uint64 unrolling_factor = calculate_unrolling_factor (max_nunits, group_size); @@ -2355,6 +2327,36 @@ vect_analyze_slp_instance (vec_info *vinfo, } } + /* If this is a reduction chain with a conversion in front + amend the SLP tree with a node for that. */ + if (!dr + && REDUC_GROUP_FIRST_ELEMENT (stmt_info) + && STMT_VINFO_DEF_TYPE (stmt_info) != vect_reduction_def) + { + /* Get at the conversion stmt - we know it's the single use + of the last stmt of the reduction chain. */ + gimple *tem = vect_orig_stmt (scalar_stmts[group_size - 1])->stmt; + use_operand_p use_p; + gimple *use_stmt; + bool r = single_imm_use (gimple_assign_lhs (tem), + &use_p, &use_stmt); + gcc_assert (r); + next_info = vinfo->lookup_stmt (use_stmt); + next_info = vect_stmt_to_vectorize (next_info); + scalar_stmts = vNULL; + scalar_stmts.create (group_size); + for (unsigned i = 0; i < group_size; ++i) + scalar_stmts.quick_push (next_info); + slp_tree conv = vect_create_new_slp_node (scalar_stmts); + SLP_TREE_CHILDREN (conv).quick_push (node); + SLP_INSTANCE_TREE (new_instance) = conv; + /* We also have to fake this conversion stmt as SLP reduction + group so we don't have to mess with too much code + elsewhere. */ + REDUC_GROUP_FIRST_ELEMENT (next_info) = next_info; + REDUC_GROUP_NEXT_ELEMENT (next_info) = NULL; + } + vinfo->slp_instances.safe_push (new_instance); if (dump_enabled_p ())