From patchwork Tue Nov 5 10:59:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1189915 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-512550-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="pFqMd+Ve"; 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 4771PJ7242z9sP4 for ; Wed, 6 Nov 2019 07:25:07 +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=PWokrTrgGi5crnUyac/pJsl9WNUbJ 8CmnhJB/XpfxAth2xpP24OQsVE87IKuMuo14k1tqhX1WeGpDXtgp34fm7TpZ3AH6 ExXsuDO5XMufBFt3BtR04SPDAu5gl7Wl6QjtpAqiTHLngaRidlEmc29M4VFE0wWz yXfrsD/LxgBa6I= 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=DfKbJnqNdCVRyraWVZA+v5/BHrQ=; b=pFq Md+VeDNiiiACyb702JzMBj0ji6HtMu3mqq2Xso7xCWZuw0mdOFG2K3B1q+5xS5jL p158i09NiagVgxVlMzIPzJa+guF/9blnQzcrcOjUeuoXrCfNwUSdMYOolPVeDZKP /RAvqlwCsF1qgR6MWwaevD9XVmxU9Ca/xE0UC0Ds= Received: (qmail 81961 invoked by alias); 5 Nov 2019 20:25:00 -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 81940 invoked by uid 89); 5 Nov 2019 20:24:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy= X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.110.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Nov 2019 20:24:58 +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 336A3311 for ; Tue, 5 Nov 2019 12:24:56 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6DFB73FDF5 for ; Tue, 5 Nov 2019 02:59:17 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [11a/n] Avoid retrying with the same vector modes References: Date: Tue, 05 Nov 2019 10:59:16 +0000 In-Reply-To: (Richard Sandiford's message of "Fri, 25 Oct 2019 13:30:08 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Patch 12/n makes the AArch64 port add four entries to autovectorize_vector_modes. Each entry describes a different vector mode assignment for vector code that mixes 8-bit, 16-bit, 32-bit and 64-bit elements. But if (as usual) the vector code has fewer element sizes than that, we could end up trying the same combination of vector modes multiple times. This patch adds a check to prevent that. As before: each patch tested individually on aarch64-linux-gnu and the series as a whole on x86_64-linux-gnu. 2019-11-04 Richard Sandiford gcc/ * tree-vectorizer.h (vec_info::mode_set): New typedef. (vec_info::used_vector_mode): New member variable. (vect_chooses_same_modes_p): Declare. * tree-vect-stmts.c (get_vectype_for_scalar_type): Record each chosen vector mode in vec_info::used_vector_mode. (vect_chooses_same_modes_p): New function. * tree-vect-loop.c (vect_analyze_loop): Use it to avoid trying the same vector statements multiple times. * tree-vect-slp.c (vect_slp_bb_region): Likewise. Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2019-11-05 10:48:11.246092351 +0000 +++ gcc/tree-vectorizer.h 2019-11-05 10:57:41.662071145 +0000 @@ -298,6 +298,7 @@ typedef std::pair vec_object /* Vectorizer state common between loop and basic-block vectorization. */ class vec_info { public: + typedef hash_set > mode_set; enum vec_kind { bb, loop }; vec_info (vec_kind, void *, vec_info_shared *); @@ -335,6 +336,9 @@ typedef std::pair vec_object /* Cost data used by the target cost model. */ void *target_cost_data; + /* The set of vector modes used in the vectorized region. */ + mode_set used_vector_modes; + /* The argument we should pass to related_vector_mode when looking up the vector mode for a scalar mode, or VOIDmode if we haven't yet made any decisions about which vector modes to use. */ @@ -1615,6 +1619,7 @@ extern tree get_related_vectype_for_scal extern tree get_vectype_for_scalar_type (vec_info *, tree); extern tree get_mask_type_for_scalar_type (vec_info *, tree); extern tree get_same_sized_vectype (tree, tree); +extern bool vect_chooses_same_modes_p (vec_info *, machine_mode); extern bool vect_get_loop_mask_type (loop_vec_info); extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *, stmt_vec_info * = NULL, gimple ** = NULL); Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2019-11-05 10:48:11.242092379 +0000 +++ gcc/tree-vect-stmts.c 2019-11-05 10:57:41.662071145 +0000 @@ -11235,6 +11235,10 @@ get_vectype_for_scalar_type (vec_info *v scalar_type); if (vectype && vinfo->vector_mode == VOIDmode) vinfo->vector_mode = TYPE_MODE (vectype); + + if (vectype) + vinfo->used_vector_modes.add (TYPE_MODE (vectype)); + return vectype; } @@ -11274,6 +11278,20 @@ get_same_sized_vectype (tree scalar_type scalar_type, nunits); } +/* Return true if replacing LOOP_VINFO->vector_mode with VECTOR_MODE + would not change the chosen vector modes. */ + +bool +vect_chooses_same_modes_p (vec_info *vinfo, machine_mode vector_mode) +{ + for (vec_info::mode_set::iterator i = vinfo->used_vector_modes.begin (); + i != vinfo->used_vector_modes.end (); ++i) + if (!VECTOR_MODE_P (*i) + || related_vector_mode (vector_mode, GET_MODE_INNER (*i), 0) != *i) + return false; + return true; +} + /* Function vect_is_simple_use. Input: Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2019-11-05 10:48:11.238092407 +0000 +++ gcc/tree-vect-loop.c 2019-11-05 10:57:41.658071173 +0000 @@ -2430,6 +2430,19 @@ vect_analyze_loop (class loop *loop, vec } loop->aux = NULL; + + if (!fatal) + while (mode_i < vector_modes.length () + && vect_chooses_same_modes_p (loop_vinfo, vector_modes[mode_i])) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "***** The result for vector mode %s would" + " be the same\n", + GET_MODE_NAME (vector_modes[mode_i])); + mode_i += 1; + } + if (res) { LOOP_VINFO_VECTORIZABLE_P (loop_vinfo) = 1; Index: gcc/tree-vect-slp.c =================================================================== --- gcc/tree-vect-slp.c 2019-11-05 10:48:11.242092379 +0000 +++ gcc/tree-vect-slp.c 2019-11-05 10:57:41.662071145 +0000 @@ -3238,6 +3238,18 @@ vect_slp_bb_region (gimple_stmt_iterator if (mode_i == 0) autodetected_vector_mode = bb_vinfo->vector_mode; + if (!fatal) + while (mode_i < vector_modes.length () + && vect_chooses_same_modes_p (bb_vinfo, vector_modes[mode_i])) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_NOTE, vect_location, + "***** The result for vector mode %s would" + " be the same\n", + GET_MODE_NAME (vector_modes[mode_i])); + mode_i += 1; + } + delete bb_vinfo; if (mode_i < vector_modes.length ()