From patchwork Mon Oct 23 17:27:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116810 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4891628qgn; Mon, 23 Oct 2017 10:27:32 -0700 (PDT) X-Received: by 10.159.229.203 with SMTP id t11mr10869801plq.190.1508779652535; Mon, 23 Oct 2017 10:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508779652; cv=none; d=google.com; s=arc-20160816; b=dimKnlDk8DFQU3znzQk5YGNkc/SZRzy0bDP0fFMVFoKTYj48+tcACOHBtn+dFjzyd8 4SFFKwRDf6fEQkkESZQT82CbN8hgWvbmVj4EU6svFjo+CcXnItLuFuPz1zIx7GbgmQV0 3Kmc6lIPLh24x6z1q0mm4oEWXZK25+sDTXe191fZLVpay536x/hnAz9P8S++0TbGzisP iGfg8idpEVnTVuqZ3fkZJdKMjg3yIWYkR/f347hzHouJ8pYVV8rts9/X3nnMrzv1tk54 CCLgzWUSNrQacf5NzQk9+5zZM4Sbfst4yyNfXn4XrTqGU49t72HL/On8OoYPLGFLXjJC 7DXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :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=/kPT1zgxiOuy5RGcgag/Yz8nKsxiWLvHADzXaN4U2ic=; b=Gw6WJpCtBsiOV24oEjlgDtEdYoncQx1nIa8t7HBTC5nSlr2kQ31txIvhl5fP67JAwa wLHjqL0JS9k8vpCSaGmPZW+Zvv7rL31aWdqsfFCzIXaSBucGln7MJFI+J0T+j+zIf3q0 cBrx/B5idBzhjCzaRCtUpewnQL1wE1YoJkIMFYa9C5W8lnMDzYHCLfBddNw+H+cMUlkV LnQm2b1LbuwV5Y4pdPknCuPksBZtTyZ+tlWQ4aXjPXiCjvpYXJJdfryVGrbs+ORTlOzt R8XPK8618/WNMogKv3v/Kk4xPWkcvE1wSPwNN4iFkuwoIVPUlLR++dWEI7LDgya+BYOu UAew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=HCTAxbjZ; spf=pass (google.com: domain of gcc-patches-return-464841-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464841-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 m25si16960pgn.588.2017.10.23.10.27.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 10:27:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464841-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=HCTAxbjZ; spf=pass (google.com: domain of gcc-patches-return-464841-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464841-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:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=L0NlmmCcQzQNnV+f1vdIUc60+W4uT HTZFXIiRrVToWlKLVYdLdVR1g4g+8/FGDdMMOjbXINaVctEVrmsfgRmX5i2RkOPA fyLacmAGs5D76i0vMBmO2aXjtAQWvll3sbizpbOfQXdT4/RuxvbUYZkn457T9iiq iOZysER8Hwh88A= 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:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=jK9iJorHTM8o3zQhkLbTWNbDAv4=; b=HCT AxbjZuEATNuBoJDBbsqrCgJIEY1lj/HwG38iYm/ZMFjWvkft5qhjti/0QXNvo0jP mCxG+mIAVegD7DU+iDWJS7SSPsqbZgh1ocCffBKIz1c2NiiiX4s1vK4bwaFQX3p+ /c/nSQF6m+Tyi7F8N0l/Yu5RJ3lcqH11WlpeT+ZE= Received: (qmail 18709 invoked by alias); 23 Oct 2017 17:27:11 -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 17238 invoked by uid 89); 23 Oct 2017 17:27:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 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=gathering X-HELO: mail-wr0-f180.google.com Received: from mail-wr0-f180.google.com (HELO mail-wr0-f180.google.com) (209.85.128.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 17:27:04 +0000 Received: by mail-wr0-f180.google.com with SMTP id o44so18164168wrf.11 for ; Mon, 23 Oct 2017 10:27:04 -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:references:date :in-reply-to:message-id:user-agent:mime-version; bh=/kPT1zgxiOuy5RGcgag/Yz8nKsxiWLvHADzXaN4U2ic=; b=PEqyWtqaw+mFnwRBHrBXIbW0k3W45MMaNuIT9b8eEZJlyrBAZyTW73VJ1wNpiESPOU yX+5xxQ5IAXWUTOnA6HnzerEYnYUbfxLKEL0DcX1czlUTs1MyxUs+4f0Z8Ep9MzH002p ShjsCuQToN3btUCQX0FOyhPjzZ5ol3MEKydjZebyyDxl5/JcA8of7TI+9rvivMfmJF8I J+saXdeXwucXzdiBOIvAcSymaOEaLey1wI7yJWeG6yiSV09uYvyplNhduSw6LwbVBNy8 pjT/8i6dySurFwKyZ3cpb4B0RupZA+G8+Fkb9EDcXeLo3x7l7kwkci8cbc4KP0oBottl gWlw== X-Gm-Message-State: AMCzsaUpU2YiHhUJzwciZnkWhx9pmF82Y2EHCcP4uHLYQ1Mn619QG4Ro rtFxGj+lxBNwNb1XmEIH/gK/irgetIY= X-Google-Smtp-Source: ABhQp+SGtSSgnITSW1aCoyR8SERuUAvwD5uvqINBtY0iJLXDwMJFsH3IeDTAerpX3iyZAiUD5pHoDQ== X-Received: by 10.223.200.134 with SMTP id k6mr5771580wrh.159.1508779622291; Mon, 23 Oct 2017 10:27:02 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id k13sm4732096wrd.95.2017.10.23.10.27.01 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 10:27:01 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [065/nnn] poly_int: vect_nunits_for_cost References: <871sltvm7r.fsf@linaro.org> Date: Mon, 23 Oct 2017 18:27:00 +0100 In-Reply-To: <871sltvm7r.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 17:54:32 +0100") Message-ID: <873769kc63.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch adds a function for getting the number of elements in a vector for cost purposes, which is always constant. It makes it possible for a later patch to change GET_MODE_NUNITS and TYPE_VECTOR_SUBPARTS to a poly_int. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vectorizer.h (vect_nunits_for_cost): New function. * tree-vect-loop.c (vect_model_reduction_cost): Use it. * tree-vect-slp.c (vect_analyze_slp_cost_1): Likewise. (vect_analyze_slp_cost): Likewise. * tree-vect-stmts.c (vect_model_store_cost): Likewise. (vect_model_load_cost): Likewise. Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2017-10-23 17:22:26.575499779 +0100 +++ gcc/tree-vectorizer.h 2017-10-23 17:22:28.837953732 +0100 @@ -1154,6 +1154,16 @@ vect_vf_for_cost (loop_vec_info loop_vin return estimated_poly_value (LOOP_VINFO_VECT_FACTOR (loop_vinfo)); } +/* Estimate the number of elements in VEC_TYPE for costing purposes. + Pick a reasonable estimate if the exact number isn't known at + compile time. */ + +static inline unsigned int +vect_nunits_for_cost (tree vec_type) +{ + return estimated_poly_value (TYPE_VECTOR_SUBPARTS (vec_type)); +} + /* Return the size of the value accessed by unvectorized data reference DR. This is only valid once STMT_VINFO_VECTYPE has been calculated for the associated gimple statement, since that guarantees that DR accesses Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2017-10-23 17:22:26.573499378 +0100 +++ gcc/tree-vect-loop.c 2017-10-23 17:22:28.835953330 +0100 @@ -3844,13 +3844,15 @@ vect_model_reduction_cost (stmt_vec_info } else if (STMT_VINFO_VEC_REDUCTION_TYPE (stmt_info) == COND_REDUCTION) { - unsigned nunits = TYPE_VECTOR_SUBPARTS (vectype); + unsigned estimated_nunits = vect_nunits_for_cost (vectype); /* Extraction of scalar elements. */ - epilogue_cost += add_stmt_cost (target_cost_data, 2 * nunits, + epilogue_cost += add_stmt_cost (target_cost_data, + 2 * estimated_nunits, vec_to_scalar, stmt_info, 0, vect_epilogue); /* Scalar max reductions via COND_EXPR / MAX_EXPR. */ - epilogue_cost += add_stmt_cost (target_cost_data, 2 * nunits - 3, + epilogue_cost += add_stmt_cost (target_cost_data, + 2 * estimated_nunits - 3, scalar_stmt, stmt_info, 0, vect_epilogue); } Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2017-10-23 17:22:27.793744215 +0100 +++ gcc/tree-vect-slp.c 2017-10-23 17:22:28.836953531 +0100 @@ -1718,8 +1718,8 @@ vect_analyze_slp_cost_1 (slp_instance in &n_perms); record_stmt_cost (body_cost_vec, n_perms, vec_perm, stmt_info, 0, vect_body); - unsigned nunits - = TYPE_VECTOR_SUBPARTS (STMT_VINFO_VECTYPE (stmt_info)); + unsigned assumed_nunits + = vect_nunits_for_cost (STMT_VINFO_VECTYPE (stmt_info)); /* And adjust the number of loads performed. This handles redundancies as well as loads that are later dead. */ auto_sbitmap perm (GROUP_SIZE (stmt_info)); @@ -1730,7 +1730,7 @@ vect_analyze_slp_cost_1 (slp_instance in bool load_seen = false; for (i = 0; i < GROUP_SIZE (stmt_info); ++i) { - if (i % nunits == 0) + if (i % assumed_nunits == 0) { if (load_seen) ncopies_for_cost++; @@ -1743,7 +1743,7 @@ vect_analyze_slp_cost_1 (slp_instance in ncopies_for_cost++; gcc_assert (ncopies_for_cost <= (GROUP_SIZE (stmt_info) - GROUP_GAP (stmt_info) - + nunits - 1) / nunits); + + assumed_nunits - 1) / assumed_nunits); poly_uint64 uf = SLP_INSTANCE_UNROLLING_FACTOR (instance); ncopies_for_cost *= estimated_poly_value (uf); } @@ -1856,9 +1856,9 @@ vect_analyze_slp_cost (slp_instance inst assumed_vf = vect_vf_for_cost (STMT_VINFO_LOOP_VINFO (stmt_info)); else assumed_vf = 1; - unsigned nunits = TYPE_VECTOR_SUBPARTS (STMT_VINFO_VECTYPE (stmt_info)); /* For reductions look at a reduction operand in case the reduction operation is widening like DOT_PROD or SAD. */ + tree vectype_for_cost = STMT_VINFO_VECTYPE (stmt_info); if (!STMT_VINFO_GROUPED_ACCESS (stmt_info)) { gimple *stmt = SLP_TREE_SCALAR_STMTS (node)[0]; @@ -1866,14 +1866,16 @@ vect_analyze_slp_cost (slp_instance inst { case DOT_PROD_EXPR: case SAD_EXPR: - nunits = TYPE_VECTOR_SUBPARTS (get_vectype_for_scalar_type - (TREE_TYPE (gimple_assign_rhs1 (stmt)))); + vectype_for_cost = get_vectype_for_scalar_type + (TREE_TYPE (gimple_assign_rhs1 (stmt))); break; default:; } } - ncopies_for_cost = least_common_multiple (nunits, - group_size * assumed_vf) / nunits; + unsigned int assumed_nunits = vect_nunits_for_cost (vectype_for_cost); + ncopies_for_cost = (least_common_multiple (assumed_nunits, + group_size * assumed_vf) + / assumed_nunits); prologue_cost_vec.create (10); body_cost_vec.create (10); Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2017-10-23 17:22:26.574499579 +0100 +++ gcc/tree-vect-stmts.c 2017-10-23 17:22:28.837953732 +0100 @@ -950,18 +950,25 @@ vect_model_store_cost (stmt_vec_info stm /* Costs of the stores. */ if (memory_access_type == VMAT_ELEMENTWISE || memory_access_type == VMAT_GATHER_SCATTER) - /* N scalar stores plus extracting the elements. */ - inside_cost += record_stmt_cost (body_cost_vec, - ncopies * TYPE_VECTOR_SUBPARTS (vectype), - scalar_store, stmt_info, 0, vect_body); + { + /* N scalar stores plus extracting the elements. */ + unsigned int assumed_nunits = vect_nunits_for_cost (vectype); + inside_cost += record_stmt_cost (body_cost_vec, + ncopies * assumed_nunits, + scalar_store, stmt_info, 0, vect_body); + } else vect_get_store_cost (dr, ncopies, &inside_cost, body_cost_vec); if (memory_access_type == VMAT_ELEMENTWISE || memory_access_type == VMAT_STRIDED_SLP) - inside_cost += record_stmt_cost (body_cost_vec, - ncopies * TYPE_VECTOR_SUBPARTS (vectype), - vec_to_scalar, stmt_info, 0, vect_body); + { + /* N scalar stores plus extracting the elements. */ + unsigned int assumed_nunits = vect_nunits_for_cost (vectype); + inside_cost += record_stmt_cost (body_cost_vec, + ncopies * assumed_nunits, + vec_to_scalar, stmt_info, 0, vect_body); + } if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, @@ -1081,8 +1088,9 @@ vect_model_load_cost (stmt_vec_info stmt { /* N scalar loads plus gathering them into a vector. */ tree vectype = STMT_VINFO_VECTYPE (stmt_info); + unsigned int assumed_nunits = vect_nunits_for_cost (vectype); inside_cost += record_stmt_cost (body_cost_vec, - ncopies * TYPE_VECTOR_SUBPARTS (vectype), + ncopies * assumed_nunits, scalar_load, stmt_info, 0, vect_body); } else