From patchwork Mon Nov 8 10:43:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 47203 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFC3E3858034 for ; Mon, 8 Nov 2021 10:43:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFC3E3858034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636368238; bh=EGvq5Y6EjrIdlIvXzJN+oBR/Goe6h+rkKXByB7bmcJ8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jlso4kvUT8YtwTc3d7j3GPgWWOhjb583XGBDxp7NXmeMyQ6N6EoNI8uQU3zYd8mbh YofjPcbplCWfhD/gmF/HechOftkHi70N9Dy2O6XymU+Uo+ZOmkiasc4DDfKMw2M3H1 BJlUXWDuUnUVL+jkpv7FPXC2He4FkdIX7cD8qgZs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 3B9B43858029 for ; Mon, 8 Nov 2021 10:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B9B43858029 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E2BF1D6E for ; Mon, 8 Nov 2021 02:43:24 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.88]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 89F293F800 for ; Mon, 8 Nov 2021 02:43:24 -0800 (PST) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH] vect: Remove vec_outside/inside_cost fields Date: Mon, 08 Nov 2021 10:43:23 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The vector costs now use a common base class instead of being completely abstract. This means that there's no longer a need to record the inside and outside costs separately. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard gcc/ * tree-vectorizer.h (_loop_vec_info): Remove vec_outside_cost and vec_inside_cost. (vector_costs::outside_cost): New function. * tree-vectorizer.c (_loop_vec_info::_loop_vec_info): Update after above. (vect_estimate_min_profitable_iters): Likewise. (vect_better_loop_vinfo_p): Get the inside and outside costs from the loop_vec_infos' vector_costs. --- gcc/tree-vect-loop.c | 24 ++++++++++-------------- gcc/tree-vectorizer.h | 16 +++++++++------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index b6a631d4384..dd4a363fee5 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -840,8 +840,6 @@ _loop_vec_info::_loop_vec_info (class loop *loop_in, vec_info_shared *shared) scan_map (NULL), slp_unrolling_factor (1), single_scalar_iteration_cost (0), - vec_outside_cost (0), - vec_inside_cost (0), inner_loop_cost_factor (param_vect_inner_loop_cost_factor), vectorizable (false), can_use_partial_vectors_p (param_vect_partial_vector_usage != 0), @@ -2845,10 +2843,10 @@ vect_better_loop_vinfo_p (loop_vec_info new_loop_vinfo, /* Compute the costs by multiplying the inside costs with the factor and add the outside costs for a more complete picture. The factor is the amount of times we are expecting to iterate this epilogue. */ - old_cost = old_loop_vinfo->vec_inside_cost * old_factor; - new_cost = new_loop_vinfo->vec_inside_cost * new_factor; - old_cost += old_loop_vinfo->vec_outside_cost; - new_cost += new_loop_vinfo->vec_outside_cost; + old_cost = old_loop_vinfo->vector_costs->body_cost () * old_factor; + new_cost = new_loop_vinfo->vector_costs->body_cost () * new_factor; + old_cost += old_loop_vinfo->vector_costs->outside_cost (); + new_cost += new_loop_vinfo->vector_costs->outside_cost (); return new_cost < old_cost; } @@ -2865,8 +2863,8 @@ vect_better_loop_vinfo_p (loop_vec_info new_loop_vinfo, /* Check whether the (fractional) cost per scalar iteration is lower or higher: new_inside_cost / new_vf vs. old_inside_cost / old_vf. */ - poly_int64 rel_new = new_loop_vinfo->vec_inside_cost * old_vf; - poly_int64 rel_old = old_loop_vinfo->vec_inside_cost * new_vf; + poly_int64 rel_new = new_loop_vinfo->vector_costs->body_cost () * old_vf; + poly_int64 rel_old = old_loop_vinfo->vector_costs->body_cost () * new_vf; HOST_WIDE_INT est_rel_new_min = estimated_poly_value (rel_new, POLY_VALUE_MIN); @@ -2918,8 +2916,10 @@ vect_better_loop_vinfo_p (loop_vec_info new_loop_vinfo, /* If there's nothing to choose between the loop bodies, see whether there's a difference in the prologue and epilogue costs. */ - if (new_loop_vinfo->vec_outside_cost != old_loop_vinfo->vec_outside_cost) - return new_loop_vinfo->vec_outside_cost < old_loop_vinfo->vec_outside_cost; + auto old_outside_cost = old_loop_vinfo->vector_costs->outside_cost (); + auto new_outside_cost = new_loop_vinfo->vector_costs->outside_cost (); + if (new_outside_cost != old_outside_cost) + return new_outside_cost < old_outside_cost; return false; } @@ -4272,10 +4272,6 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo, vec_outside_cost = (int)(vec_prologue_cost + vec_epilogue_cost); - /* Stash the costs so that we can compare two loop_vec_infos. */ - loop_vinfo->vec_inside_cost = vec_inside_cost; - loop_vinfo->vec_outside_cost = vec_outside_cost; - if (dump_enabled_p ()) { dump_printf_loc (MSG_NOTE, vect_location, "Cost model analysis: \n"); diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 1cd6cc036f2..87d3f211a2e 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -724,13 +724,6 @@ public: /* Cost of a single scalar iteration. */ int single_scalar_iteration_cost; - /* The cost of the vector prologue and epilogue, including peeled - iterations and set-up code. */ - int vec_outside_cost; - - /* The cost of the vector loop body. */ - int vec_inside_cost; - /* The factor used to over weight those statements in an inner loop relative to the loop being vectorized. */ unsigned int inner_loop_cost_factor; @@ -1429,6 +1422,7 @@ public: unsigned int prologue_cost () const; unsigned int body_cost () const; unsigned int epilogue_cost () const; + unsigned int outside_cost () const; protected: unsigned int record_stmt_cost (stmt_vec_info, vect_cost_model_location, @@ -1489,6 +1483,14 @@ vector_costs::epilogue_cost () const return m_costs[vect_epilogue]; } +/* Return the cost of the prologue and epilogue code (in abstract units). */ + +inline unsigned int +vector_costs::outside_cost () const +{ + return prologue_cost () + epilogue_cost (); +} + #define VECT_MAX_COST 1000 /* The maximum number of intermediate steps required in multi-step type