From patchwork Sat Oct 19 15:06:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1179885 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-511363-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DUx+zLYP"; 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 46wX0Z2RXgz9sP3 for ; Sun, 20 Oct 2019 05:45:50 +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:date:message-id:mime-version:content-type; q=dns; s= default; b=iTh/kHmpvXmWKUr/JblCH1+0Oh4SAMbWO470eedI1wtxUMNQmtFA4 mv6/4K+GkRvVZTtSrY31TQS5ZAG8CprLErA+zJV+xe8LWhy8IHbMuEs1rUxose87 NY/tRCGpARWue4kRRvv4ZrphiL+FgXEC0NbUAv7/GQAhtbwgDVICWQ= 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=+R0Bb9U8xSAavohIs3nzs+oR5yo=; b=DUx+zLYPJWryCMHfjp4t c6oqyMjPW3lEVrGAS3vrzb1GLROmaUoVUv60kd6djCWw6WP0UlqwiVGBEcQyf709 2k3lDaI3HsUxojFLZH1AGGxrdU0CJsmgufJ6TBxKC9f6nDFmB76dMgPkfFxLKiSi P89sPwNyuiahHDqqZZ6YGxI= Received: (qmail 127004 invoked by alias); 19 Oct 2019 18:45:34 -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 126933 invoked by uid 89); 19 Oct 2019 18:45:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT autolearn=ham version=3.3.1 spammy=sk:vect_re X-HELO: foss.arm.com Received: from Unknown (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 19 Oct 2019 18:45:15 +0000 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 2C3A9495 for ; Sat, 19 Oct 2019 11:45:06 -0700 (PDT) Received: from localhost (unknown [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 748123F962 for ; Sat, 19 Oct 2019 08:06:51 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Move code out of vect_slp_analyze_bb_1 Date: Sat, 19 Oct 2019 16:06:40 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes After the previous patch, it seems more natural to apply the PARAM_SLP_MAX_INSNS_IN_BB threshold as soon as we know what the region is, rather than delaying it to vect_slp_analyze_bb_1. (But rather than carve out the biggest region possible and then reject it, wouldn't it be better to stop when the region gets too big, so we at least have a chance of vectorising something?) It also seems more natural for vect_slp_bb_region to create the bb_vec_info itself rather than (a) having to pass bits of data down for the initialisation and (b) forcing vect_slp_analyze_bb_1 to free on every failure return. Tested on aarch64-linux-gnu and x86_64-linux-gnu. OK to install? Richard 2019-10-19 Richard Sandiford gcc/ * tree-vect-slp.c (vect_slp_analyze_bb_1): Take a bb_vec_info and return a boolean success value. Move the allocation and initialization of the bb_vec_info to... (vect_slp_bb_region): ...here. Update call accordingly. (vect_slp_bb): Apply PARAM_SLP_MAX_INSNS_IN_BB here rather than in vect_slp_analyze_bb_1. Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2019-10-19 15:59:53.875379473 +0100 +++ gcc/tree-vect-slp.c 2019-10-19 16:01:13.714824484 +0100 @@ -2836,47 +2836,24 @@ vect_bb_vectorization_profitable_p (bb_v return true; } -/* Check if the basic block can be vectorized. Returns a bb_vec_info - if so and sets fatal to true if failure is independent of - current_vector_size. */ - -static bb_vec_info -vect_slp_analyze_bb_1 (gimple_stmt_iterator region_begin, - gimple_stmt_iterator region_end, - vec datarefs, int n_stmts, - bool &fatal, vec_info_shared *shared) +/* Check if the region described by BB_VINFO can be vectorized, returning + true if so. When returning false, set FATAL to true if the same failure + would prevent vectorization at other vector sizes, false if it is still + worth trying other sizes. N_STMTS is the number of statements in the + region. */ + +static bool +vect_slp_analyze_bb_1 (bb_vec_info bb_vinfo, int n_stmts, bool &fatal) { DUMP_VECT_SCOPE ("vect_slp_analyze_bb"); - bb_vec_info bb_vinfo; slp_instance instance; int i; poly_uint64 min_vf = 2; - bool first_time_p = shared->datarefs.is_empty (); /* The first group of checks is independent of the vector size. */ fatal = true; - if (n_stmts > PARAM_VALUE (PARAM_SLP_MAX_INSNS_IN_BB)) - { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "not vectorized: too many instructions in " - "basic block.\n"); - free_data_refs (datarefs); - return NULL; - } - - bb_vinfo = new _bb_vec_info (region_begin, region_end, shared); - if (!bb_vinfo) - return NULL; - - BB_VINFO_DATAREFS (bb_vinfo) = datarefs; - if (first_time_p) - bb_vinfo->shared->save_datarefs (); - else - bb_vinfo->shared->check_datarefs (); - /* Analyze the data references. */ if (!vect_analyze_data_refs (bb_vinfo, &min_vf, NULL)) @@ -2885,9 +2862,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: unhandled data-ref in basic " "block.\n"); - - delete bb_vinfo; - return NULL; + return false; } if (BB_VINFO_DATAREFS (bb_vinfo).length () < 2) @@ -2896,9 +2871,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: not enough data-refs in " "basic block.\n"); - - delete bb_vinfo; - return NULL; + return false; } if (!vect_analyze_data_ref_accesses (bb_vinfo)) @@ -2907,9 +2880,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: unhandled data access in " "basic block.\n"); - - delete bb_vinfo; - return NULL; + return false; } /* If there are no grouped stores in the region there is no need @@ -2921,9 +2892,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: no grouped stores in " "basic block.\n"); - - delete bb_vinfo; - return NULL; + return false; } /* While the rest of the analysis below depends on it in some way. */ @@ -2943,9 +2912,7 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera "not vectorized: failed to find SLP opportunities " "in basic block.\n"); } - - delete bb_vinfo; - return NULL; + return false; } vect_record_base_alignments (bb_vinfo); @@ -2976,19 +2943,14 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera i++; } if (! BB_VINFO_SLP_INSTANCES (bb_vinfo).length ()) - { - delete bb_vinfo; - return NULL; - } + return false; if (!vect_slp_analyze_operations (bb_vinfo)) { if (dump_enabled_p ()) dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: bad operation in basic block.\n"); - - delete bb_vinfo; - return NULL; + return false; } /* Cost model: check if the vectorization is worthwhile. */ @@ -2999,16 +2961,13 @@ vect_slp_analyze_bb_1 (gimple_stmt_itera dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, "not vectorized: vectorization is not " "profitable.\n"); - - delete bb_vinfo; - return NULL; + return false; } if (dump_enabled_p ()) dump_printf_loc (MSG_NOTE, vect_location, "Basic block will be vectorized using SLP\n"); - - return bb_vinfo; + return true; } /* Subroutine of vect_slp_bb. Try to vectorize the statements between @@ -3037,9 +2996,16 @@ vect_slp_bb_region (gimple_stmt_iterator { bool vectorized = false; bool fatal = false; - bb_vinfo = vect_slp_analyze_bb_1 (region_begin, region_end, - datarefs, n_stmts, fatal, &shared); - if (bb_vinfo + bb_vinfo = new _bb_vec_info (region_begin, region_end, &shared); + + bool first_time_p = shared.datarefs.is_empty (); + BB_VINFO_DATAREFS (bb_vinfo) = datarefs; + if (first_time_p) + bb_vinfo->shared->save_datarefs (); + else + bb_vinfo->shared->check_datarefs (); + + if (vect_slp_analyze_bb_1 (bb_vinfo, n_stmts, fatal) && dbg_cnt (vect_slp)) { if (dump_enabled_p ()) @@ -3132,7 +3098,14 @@ vect_slp_bb (basic_block bb) gimple_stmt_iterator region_end = gsi; - if (vect_slp_bb_region (region_begin, region_end, datarefs, insns)) + if (insns > PARAM_VALUE (PARAM_SLP_MAX_INSNS_IN_BB)) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "not vectorized: too many instructions in " + "basic block.\n"); + } + else if (vect_slp_bb_region (region_begin, region_end, datarefs, insns)) any_vectorized = true; if (gsi_end_p (region_end))