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: 829490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-464841-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="k+/nGUfE"; 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 3yLNdD1fx9z9t6C for ; Tue, 24 Oct 2017 04:27:28 +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:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=TjXULsmgc48nclBfh1DFZMWCLguca 51c+lf/UXcJkC02HV5dydK1CE43ybWRxybRkc1EpoMFm3+2lnq1Znuhqp2rJyQSI 8NyDzAag+Fagl2LYUW/EA6TfOIrIJZfXrWtSCvPCnn+EuDFhAZtZDft4no3sZm1T 12qyFbR0u1+Z+c= 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=k+/ nGUfE3HtFv32rkrNp6U4jqspwhv/UDqs1KvLnWyXJT7j0bXMxi2w1EkjwnKz0HSR rsn2ER+D5Z7sBG+rU/f+KGiUgY2NZXmOFVwSKb07XND73Pq+7KQHw7r27O8mZCy+ LwJs6ydXivt+P0UuY0uoshOvQCUvnIP4RptdBo0g= 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