From patchwork Fri Sep 15 10:43:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 112703 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp449760edb; Fri, 15 Sep 2017 03:43:41 -0700 (PDT) X-Received: by 10.98.74.217 with SMTP id c86mr24090549pfj.225.1505472221002; Fri, 15 Sep 2017 03:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505472220; cv=none; d=google.com; s=arc-20160816; b=iUK/GAJdM6cbsVo8RteKdef0yztha55HXbeIIfY+6wNiuVXRC7nefRfnhsUsSxqVn1 VhQgjtAcODWpiGwWQNNz4cB7HtgVFqCySecpk/UhW/2YtyjaQJGXatwZxUiSWbPtkyl4 MytPBOApfKQVPxSPwf39/oHZAVNeBGR6Wu+eYzwb/9eRLp5CNgAEKpsBpJqbxxykb7WD lLLlhLueKerCX5+Gmr/2NN3FgFOg6mWMd+PEQeY9DKVhkpgHPy+KKZD9HXF+/3gYjlW+ UZMvM8ut1qOKW0n0WIzAOQd4WzqpIdQiEzyoc/+i1MsKdQVFwoBzTO12eaguqxelIq23 YQmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=Pai6DjwSQsLnzsGVVIICHsXxvYQzOikJ1n+QLGlNFl0=; b=H+8ltmDQQEC9TwLMeE1bqhyJ5CMb5JFyMy5NMx7p6yKdxmZmimHpQYqrTf2H6gomTL 0q7UDNGi9TKyxplJ2RlOfoTsRU+qiBczwoDivEMRJH5Z0tE0hNUBlSX3kuEOodd3d6HQ wArtI/RRFqjcFMqygIhep4cn83TZ+UPn0vK6uKCjT/NBuJnfDHn/UtzqxoniOLqcFC1n SSns9Z19pARQfAk8rh0YaT5eUcNYAdeYBL0wxP6H8oFokIWLgMu/A4WHchw2CoUhG9C1 o5zULTGZpmw3xlWcg3yAipEWpL9c6v4bxmAiUid3TBCPRkYjeHFDp7zZFCqk7ll4/1mb ymeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kbn9zkww; spf=pass (google.com: domain of gcc-patches-return-462215-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462215-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id l4si450327pgu.396.2017.09.15.03.43.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Sep 2017 03:43:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-462215-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kbn9zkww; spf=pass (google.com: domain of gcc-patches-return-462215-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-462215-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=BUcH3wEG3ydGIyH/R6juXReHuz+Mm5xrGgdegLTKqahpbsFkug1Mc +mYNhBBbs0qTemBN63XrzAFJg+pzjsL9gZIkvoruJ08RQn7ClwvN9JLMtN+GK8Bc +J3FIGWxQSEs3J/jfyqYj1aMalYqYWkFGBqQQQyHt38Bz0p8wf01PA= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=PtccGtreS6LUYWiouxK1qDit9wY=; b=kbn9zkww2B9Y6tv7oBxg s5XbtWma97hmSNoIiyVykWie3RKSkROgNwVAee98Q8JJBiF5QFgxBdVr3TpeR19F 3JcTw3GS9NQzzy1dkrL5vuSe7wIQRJ+9OsI7ja+TzbKytaBX/mZNPxFo8lIk/smi tdCBrLvqfPKNoy781/+sgTc= Received: (qmail 107551 invoked by alias); 15 Sep 2017 10:43:27 -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 107347 invoked by uid 89); 15 Sep 2017 10:43:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Sep 2017 10:43:24 +0000 Received: by mail-wm0-f42.google.com with SMTP id v142so7146902wmv.5 for ; Fri, 15 Sep 2017 03:43:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=Pai6DjwSQsLnzsGVVIICHsXxvYQzOikJ1n+QLGlNFl0=; b=FlSc8yrTKKMZPKsA7gcPpJCiYrdq6RkK8BswMxqNNRZMKudsYCu2DQ/dcCkE/UA4wi x2zE2hNV47lwhSjjx3UNwYYQqlqE8N6nB/rYHfDz24bcvUmY/1fiv3ph1FfH4h1hSyq5 MeVMQO4D06SJSlK2l3BZRowMtnH0xlUoyOrHmoibovSkX7lJA7o0ZCdcOZ5gvBWg58A2 Q3KI0ZxWVJwhqHxzHy6DuwPZumJE3FuPga72aN3nXMuDdRDfK4a52i067cRWL9M5nebR NVqHRwZIcLzSQoJUzK6VBk18M4WyvCmQRbZQXBVIWuoLT1aPQ87KPymFE0S3KLBK2iBs P8ow== X-Gm-Message-State: AHPjjUgbv7mWoW2DiImuypM8V0dWx/Tk5sX9J91G/RScqTCinUwGWav2 5orb8Wk3XJclLTIEh/qH0FDShiAVs4g= X-Google-Smtp-Source: AOwi7QDyxrlkmcdSY2lcq1P5jvC5JXx2QAsBOR69IM3cFmfLHHaC9bOvSYb/8t4VSKrVKysg2gpnZQ== X-Received: by 10.28.183.85 with SMTP id h82mr2527996wmf.24.1505472201787; Fri, 15 Sep 2017 03:43:21 -0700 (PDT) Received: from localhost (92.40.248.1.threembb.co.uk. [92.40.248.1]) by smtp.gmail.com with ESMTPSA id s3sm497398wrg.3.2017.09.15.03.43.19 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Sep 2017 03:43:20 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Move computation of SLP_TREE_NUMBER_OF_VEC_STMTS Date: Fri, 15 Sep 2017 11:43:18 +0100 Message-ID: <87mv5wnsxl.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 Previously SLP_TREE_NUMBER_OF_VEC_STMTS was calculated while scheduling an SLP tree after analysis, but sometimes it can be useful to know the value during analysis too. This patch moves the calculation to vect_slp_analyze_node_operaions instead. This became more natural after: 2017-06-30 Richard Biener * tree-vect-slp.c (vect_slp_analyze_node_operations): Only analyze the first scalar stmt. Move vector type computation for the BB case here from ... * tree-vect-stmts.c (vect_analyze_stmt): ... here. Guard live operation processing in the SLP case properly. since the STMT_VINFO_VECTYPE is now always initialised in time. Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Richard 2017-09-15 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vectorizer.h (vect_slp_analyze_operations): Replace parameters with a vec_info *. * tree-vect-loop.c (vect_analyze_loop_operations): Update call accordingly. * tree-vect-slp.c (vect_slp_analyze_node_operations): Add vec_info * parameter. Set SLP_TREE_NUMBER_OF_VEC_STMTS here rather than in vect_schedule_slp_instance. (vect_slp_analyze_operations): Replace parameters with a vec_info *. Update call to vect_slp_analyze_node_operations. Simplify return value. (vect_slp_analyze_bb_1): Update call accordingly. (vect_schedule_slp_instance): Remove vectorization_factor parameter. Don't calculate SLP_TREE_NUMBER_OF_VEC_STMTS here. (vect_schedule_slp): Update call accordingly. Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2017-09-14 17:35:26.635276568 +0100 +++ gcc/tree-vectorizer.h 2017-09-15 11:35:46.833592065 +0100 @@ -1246,8 +1246,7 @@ extern void vect_free_slp_instance (slp_ extern bool vect_transform_slp_perm_load (slp_tree, vec , gimple_stmt_iterator *, int, slp_instance, bool, unsigned *); -extern bool vect_slp_analyze_operations (vec slp_instances, - void *); +extern bool vect_slp_analyze_operations (vec_info *); extern bool vect_schedule_slp (vec_info *); extern bool vect_analyze_slp (vec_info *, unsigned); extern bool vect_make_slp_decision (loop_vec_info); Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2017-09-14 17:35:26.635276568 +0100 +++ gcc/tree-vect-loop.c 2017-09-15 11:35:46.832592132 +0100 @@ -2031,8 +2031,7 @@ vect_analyze_loop_2 (loop_vec_info loop_ remove unsupported SLP instances which makes the above SLP kind detection invalid. */ unsigned old_size = LOOP_VINFO_SLP_INSTANCES (loop_vinfo).length (); - vect_slp_analyze_operations (LOOP_VINFO_SLP_INSTANCES (loop_vinfo), - LOOP_VINFO_TARGET_COST_DATA (loop_vinfo)); + vect_slp_analyze_operations (loop_vinfo); if (LOOP_VINFO_SLP_INSTANCES (loop_vinfo).length () != old_size) goto again; } Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2017-09-14 17:04:19.083694343 +0100 +++ gcc/tree-vect-slp.c 2017-09-15 11:35:46.833592065 +0100 @@ -2501,11 +2501,14 @@ _bb_vec_info::~_bb_vec_info () } -/* Analyze statements contained in SLP tree node after recursively analyzing - the subtree. Return TRUE if the operations are supported. */ +/* Analyze statements contained in SLP tree NODE after recursively analyzing + the subtree. NODE_INSTANCE contains NODE and VINFO contains INSTANCE. + + Return true if the operations are supported. */ static bool -vect_slp_analyze_node_operations (slp_tree node, slp_instance node_instance) +vect_slp_analyze_node_operations (vec_info *vinfo, slp_tree node, + slp_instance node_instance) { bool dummy; int i, j; @@ -2516,7 +2519,7 @@ vect_slp_analyze_node_operations (slp_tr return true; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - if (!vect_slp_analyze_node_operations (child, node_instance)) + if (!vect_slp_analyze_node_operations (vinfo, child, node_instance)) return false; stmt = SLP_TREE_SCALAR_STMTS (node)[0]; @@ -2568,6 +2571,29 @@ vect_slp_analyze_node_operations (slp_tr STMT_VINFO_VECTYPE (vinfo_for_stmt (sstmt)) = vectype; } + /* Calculate the number of vector statements to be created for the + scalar stmts in this node. For SLP reductions it is equal to the + number of vector statements in the children (which has already been + calculated by the recursive call). Otherwise it is the number of + scalar elements in one scalar iteration (GROUP_SIZE) multiplied by + VF divided by the number of elements in a vector. */ + if (GROUP_FIRST_ELEMENT (stmt_info) + && !STMT_VINFO_GROUPED_ACCESS (stmt_info)) + SLP_TREE_NUMBER_OF_VEC_STMTS (node) + = SLP_TREE_NUMBER_OF_VEC_STMTS (SLP_TREE_CHILDREN (node)[0]); + else + { + int vf; + if (loop_vec_info loop_vinfo = dyn_cast (vinfo)) + vf = loop_vinfo->vectorization_factor; + else + vf = 1; + unsigned int group_size = SLP_INSTANCE_GROUP_SIZE (node_instance); + tree vectype = STMT_VINFO_VECTYPE (stmt_info); + SLP_TREE_NUMBER_OF_VEC_STMTS (node) + = vf * group_size / TYPE_VECTOR_SUBPARTS (vectype); + } + /* Push SLP node def-type to stmt operands. */ FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), j, child) if (SLP_TREE_DEF_TYPE (child) != vect_internal_def) @@ -2586,11 +2612,11 @@ vect_slp_analyze_node_operations (slp_tr } -/* Analyze statements in SLP instances of the basic block. Return TRUE if the +/* Analyze statements in SLP instances of VINFO. Return true if the operations are supported. */ bool -vect_slp_analyze_operations (vec slp_instances, void *data) +vect_slp_analyze_operations (vec_info *vinfo) { slp_instance instance; int i; @@ -2599,9 +2625,10 @@ vect_slp_analyze_operations (vecslp_instances.iterate (i, &instance); ) { - if (!vect_slp_analyze_node_operations (SLP_INSTANCE_TREE (instance), + if (!vect_slp_analyze_node_operations (vinfo, + SLP_INSTANCE_TREE (instance), instance)) { dump_printf_loc (MSG_NOTE, vect_location, @@ -2610,20 +2637,17 @@ vect_slp_analyze_operations (vecslp_instances.ordered_remove (i); } else { /* Compute the costs of the SLP instance. */ - vect_analyze_slp_cost (instance, data); + vect_analyze_slp_cost (instance, vinfo->target_cost_data); i++; } } - if (!slp_instances.length ()) - return false; - - return true; + return !vinfo->slp_instances.is_empty (); } @@ -2897,8 +2921,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera return NULL; } - if (!vect_slp_analyze_operations (BB_VINFO_SLP_INSTANCES (bb_vinfo), - BB_VINFO_TARGET_COST_DATA (bb_vinfo))) + if (!vect_slp_analyze_operations (bb_vinfo)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, @@ -3652,14 +3675,13 @@ vect_transform_slp_perm_load (slp_tree n /* Vectorize SLP instance tree in postorder. */ static bool -vect_schedule_slp_instance (slp_tree node, slp_instance instance, - unsigned int vectorization_factor) +vect_schedule_slp_instance (slp_tree node, slp_instance instance) { gimple *stmt; bool grouped_store, is_store; gimple_stmt_iterator si; stmt_vec_info stmt_info; - unsigned int vec_stmts_size, nunits, group_size; + unsigned int group_size; tree vectype; int i, j; slp_tree child; @@ -3668,7 +3690,7 @@ vect_schedule_slp_instance (slp_tree nod return false; FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) - vect_schedule_slp_instance (child, instance, vectorization_factor); + vect_schedule_slp_instance (child, instance); /* Push SLP node def-type to stmts. */ FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child) @@ -3681,27 +3703,10 @@ vect_schedule_slp_instance (slp_tree nod /* VECTYPE is the type of the destination. */ vectype = STMT_VINFO_VECTYPE (stmt_info); - nunits = (unsigned int) TYPE_VECTOR_SUBPARTS (vectype); group_size = SLP_INSTANCE_GROUP_SIZE (instance); - /* For each SLP instance calculate number of vector stmts to be created - for the scalar stmts in each node of the SLP tree. Number of vector - elements in one vector iteration is the number of scalar elements in - one scalar iteration (GROUP_SIZE) multiplied by VF divided by vector - size. - Unless this is a SLP reduction in which case the number of vector - stmts is equal to the number of vector stmts of the children. */ - if (GROUP_FIRST_ELEMENT (stmt_info) - && !STMT_VINFO_GROUPED_ACCESS (stmt_info)) - vec_stmts_size = SLP_TREE_NUMBER_OF_VEC_STMTS (SLP_TREE_CHILDREN (node)[0]); - else - vec_stmts_size = (vectorization_factor * group_size) / nunits; - if (!SLP_TREE_VEC_STMTS (node).exists ()) - { - SLP_TREE_VEC_STMTS (node).create (vec_stmts_size); - SLP_TREE_NUMBER_OF_VEC_STMTS (node) = vec_stmts_size; - } + SLP_TREE_VEC_STMTS (node).create (SLP_TREE_NUMBER_OF_VEC_STMTS (node)); if (dump_enabled_p ()) { @@ -3850,20 +3855,15 @@ vect_schedule_slp (vec_info *vinfo) { vec slp_instances; slp_instance instance; - unsigned int i, vf; + unsigned int i; bool is_store = false; slp_instances = vinfo->slp_instances; - if (is_a (vinfo)) - vf = as_a (vinfo)->vectorization_factor; - else - vf = 1; - FOR_EACH_VEC_ELT (slp_instances, i, instance) { /* Schedule the tree of INSTANCE. */ is_store = vect_schedule_slp_instance (SLP_INSTANCE_TREE (instance), - instance, vf); + instance); if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "vectorizing stmts using SLP.\n");