From patchwork Wed Nov 8 15:12:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 118274 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5410325qgn; Wed, 8 Nov 2017 07:12:50 -0800 (PST) X-Google-Smtp-Source: ABhQp+TGVJD1sTz0XhfqAw4mh26RQgNv3HXnh+yWwmk3Iw7e9yF90rJibZl9SqWoPY0P6f37GnVl X-Received: by 10.99.147.69 with SMTP id w5mr750993pgm.401.1510153970535; Wed, 08 Nov 2017 07:12:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510153970; cv=none; d=google.com; s=arc-20160816; b=xFpI4ZuUCB/LNTSqlkvSzBu3Oftto30hwM613Qq9efA5ladI7T7UKEg5SkoxhTqVTf pbXHi3hSTyvOrSpVn3zlDM8NmHZsbZkX6R+AXXydBbPTWWynPT0XUwgmsSsy2/eI9NbS u3z3vfgebl1B+EUxWTe84iDAzzfT+vY/MzEBC66t/7TsGLKgeZOaB1GZsJtxQTcNU/CC MD44ZQXr/a2YhmImN8l8m0eO4fIrsew6Qw9GnK5/1aZ5k4DTSkUk0zyp8YxKqSTCdpJd uWkcrTzbLedQNZMBlkWy776UVpG5+X+WiTpQiuEw5z5gP3woPMKnBNiZqk2OeLuGmQYz mzcg== 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:cc: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=aeF3/GfiAPPIulitVdp7JWfQSudNMp5+SgLvJa1IJok=; b=RMEk7edPCvIMWNbpCseivnIssCzsLygwxiqLUpd7NoR6R4ZCqrdZufYtYNl6H0EDE4 raTCfcZZMXo0Vbo/gxTGlEvFzkojRU7Oc2RE2SQLEqUDE148tBfwRqxuYoZeE593WC8n gogsR2DEafHvNoEqGK2qrYUMleHWu2f9P7iBu5cxdafGuzCrPelV6Bbarw1L395TcbjL 0d3/JFwUYGPw5mKQ1jFlZjrpWxJaYVJJnbBrPh2dSs9fMvKguWLBndPqNrNm4BQhtXYE rYnwA7coUwDp3khUjQ46MSxJUtyQk2mDvp7D9u1yCU04D1Z8igF4LLL7OwcuEWl0WIo9 NdsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uLQoaPB4; spf=pass (google.com: domain of gcc-patches-return-466252-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466252-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 r85si4400773pfl.178.2017.11.08.07.12.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 07:12:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-466252-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=uLQoaPB4; spf=pass (google.com: domain of gcc-patches-return-466252-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466252-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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=default; b=AVJSfgIK5K1HmISS WLxnrM03iH8O/X/8jK6UGVkBBo5G0mZZat0GvSHnb24kLeHvNaAR688ZW458hizb PDcIAUtQCCbM3kaG81T5AG6+vwk7qX3/xKebgfMYb2MkbawH4Tt6Fw7HfFxlCIf0 LDCewphNXj9GzTv+/EDDPSc8Mko= 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:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; s=default; bh=QoW03lckE4/fKbM6OfI2Mw CoAvM=; b=uLQoaPB4NzN/pUBcWFOR1RsMlDGb4umKiKd2YTkcz45scdKw4jB/oe xRwOm7RZJPZJmh+8tKGJ0l+5Tm4834GXDYE/p3yPD3///awJtLc2QnK7qWvWsTei 6UlmwRrLN1Ywi0VT8tOExu8pXbe5SQ53OBV5sJtpgcxLlWBqkHm2w= Received: (qmail 75478 invoked by alias); 8 Nov 2017 15:12: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 75442 invoked by uid 89); 8 Nov 2017 15:12:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_BLACK autolearn=ham version=3.3.2 spammy=6023 X-HELO: mail-wm0-f46.google.com Received: from mail-wm0-f46.google.com (HELO mail-wm0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Nov 2017 15:12:30 +0000 Received: by mail-wm0-f46.google.com with SMTP id r196so11516741wmf.2 for ; Wed, 08 Nov 2017 07:12:30 -0800 (PST) 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:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version; bh=aeF3/GfiAPPIulitVdp7JWfQSudNMp5+SgLvJa1IJok=; b=BCcYnKp/kXNadUoFAjubxYWpJnCIBtC+sPt3SsSHUU5MuY7J1sLzSEve2st+d7SMrS MGiJun/ToiDCFwlcOpLQUob/bpR0mJHpQYeLzbSrzD7RYEaTKI2RXHZLPZWtqc/SSm1H KU0alLMm340OHli5ORba9vR34dqk6UdqSUPVdVT6jF/BmxTnCmPDipQaIfMthnwsm7cj TUGcgvjVjfyxC93wyjK0C9POVp8S0Vq4JrpKvecPWDmpBhKaytRNXPmGc/NB8pVFyYS3 sandtXsnARXni/rd0nTkNgeJx72E6XlmznczPM0PUuxWNh03nAiL6aBgncZEEdeADAZE uLUA== X-Gm-Message-State: AJaThX6O9/GFNH7LPeNlKa+JZjgTBlfPdTkF4Afp0ZAgvj7oh3Wb4fQv QuXFcxakM2J7OGizNWcwtqQFTg== X-Received: by 10.28.229.149 with SMTP id c143mr628307wmh.156.1510153948187; Wed, 08 Nov 2017 07:12:28 -0800 (PST) Received: from localhost (94.197.121.218.threembb.co.uk. [94.197.121.218]) by smtp.gmail.com with ESMTPSA id u18sm6071526wrg.94.2017.11.08.07.12.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Nov 2017 07:12:27 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com, richard.sandiford@linaro.org Cc: richard.earnshaw@arm.com, james.greenhalgh@arm.com, marcus.shawcroft@arm.com Subject: [1/4] Give the target more control over ARRAY_TYPE modes References: <87375oyfen.fsf@linaro.org> Date: Wed, 08 Nov 2017 15:12:23 +0000 In-Reply-To: <87375oyfen.fsf@linaro.org> (Richard Sandiford's message of "Wed, 08 Nov 2017 15:10:56 +0000") Message-ID: <87y3ngx0rs.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 So far we've used integer modes for LD[234] and ST[234] arrays. That doesn't scale well to SVE, since the sizes aren't fixed at compile time (and even if they were, we wouldn't want integers to be so wide). This patch lets the target use double-, triple- and quadruple-length vectors instead. 2017-11-08 Richard Sandiford Alan Hayward David Sherwood gcc/ * target.def (array_mode): New target hook. * doc/tm.texi.in (TARGET_ARRAY_MODE): New hook. * doc/tm.texi: Regenerate. * hooks.h (hook_optmode_mode_uhwi_none): Declare. * hooks.c (hook_optmode_mode_uhwi_none): New function. * tree-vect-data-refs.c (vect_lanes_optab_supported_p): Use targetm.array_mode. * stor-layout.c (mode_for_array): Likewise. Support polynomial type sizes. Index: gcc/target.def =================================================================== --- gcc/target.def 2017-11-08 15:05:33.783582091 +0000 +++ gcc/target.def 2017-11-08 15:06:16.086850270 +0000 @@ -3400,6 +3400,22 @@ the vector element type.", HOST_WIDE_INT, (const_tree type), default_vector_alignment) +DEFHOOK +(array_mode, + "Return the mode that GCC should use for an array that has\n\ +@var{nelems} elements, with each element having mode @var{mode}.\n\ +Return no mode if the target has no special requirements. In the\n\ +latter case, GCC looks for an integer mode of the appropriate size\n\ +if available and uses BLKmode otherwise. Usually the search for the\n\ +integer mode is limited to @code{MAX_FIXED_MODE_SIZE}, but the\n\ +@code{TARGET_ARRAY_MODE_SUPPORTED_P} hook allows a larger mode to be\n\ +used in specific cases.\n\ +\n\ +The main use of this hook is to specify that an array of vectors should\n\ +also have a vector mode. The default implementation returns no mode.", + opt_machine_mode, (machine_mode mode, unsigned HOST_WIDE_INT nelems), + hook_optmode_mode_uhwi_none) + /* True if we should try to use a scalar mode to represent an array, overriding the usual MAX_FIXED_MODE limit. */ DEFHOOK Index: gcc/doc/tm.texi.in =================================================================== --- gcc/doc/tm.texi.in 2017-11-08 15:05:32.663824754 +0000 +++ gcc/doc/tm.texi.in 2017-11-08 15:06:16.085850270 +0000 @@ -3322,6 +3322,8 @@ stack. @hook TARGET_VECTOR_MODE_SUPPORTED_P +@hook TARGET_ARRAY_MODE + @hook TARGET_ARRAY_MODE_SUPPORTED_P @hook TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P Index: gcc/doc/tm.texi =================================================================== --- gcc/doc/tm.texi 2017-11-08 15:05:33.777173014 +0000 +++ gcc/doc/tm.texi 2017-11-08 15:06:16.084850270 +0000 @@ -4243,6 +4243,20 @@ insns involving vector mode @var{mode}. must have move patterns for this mode. @end deftypefn +@deftypefn {Target Hook} opt_machine_mode TARGET_ARRAY_MODE (machine_mode @var{mode}, unsigned HOST_WIDE_INT @var{nelems}) +Return the mode that GCC should use for an array that has +@var{nelems} elements, with each element having mode @var{mode}. +Return no mode if the target has no special requirements. In the +latter case, GCC looks for an integer mode of the appropriate size +if available and uses BLKmode otherwise. Usually the search for the +integer mode is limited to @code{MAX_FIXED_MODE_SIZE}, but the +@code{TARGET_ARRAY_MODE_SUPPORTED_P} hook allows a larger mode to be +used in specific cases. + +The main use of this hook is to specify that an array of vectors should +also have a vector mode. The default implementation returns no mode. +@end deftypefn + @deftypefn {Target Hook} bool TARGET_ARRAY_MODE_SUPPORTED_P (machine_mode @var{mode}, unsigned HOST_WIDE_INT @var{nelems}) Return true if GCC should try to use a scalar mode to store an array of @var{nelems} elements, given that each element has mode @var{mode}. Index: gcc/hooks.h =================================================================== --- gcc/hooks.h 2017-11-08 15:05:32.622623544 +0000 +++ gcc/hooks.h 2017-11-08 15:06:16.085850270 +0000 @@ -124,4 +124,7 @@ extern const char *hook_constcharptr_con extern const char *hook_constcharptr_const_tree_const_tree_null (const_tree, const_tree); extern const char *hook_constcharptr_int_const_tree_null (int, const_tree); extern const char *hook_constcharptr_int_const_tree_const_tree_null (int, const_tree, const_tree); + +extern opt_machine_mode hook_optmode_mode_uhwi_none (machine_mode, + unsigned HOST_WIDE_INT); #endif Index: gcc/hooks.c =================================================================== --- gcc/hooks.c 2017-11-08 15:05:32.622623544 +0000 +++ gcc/hooks.c 2017-11-08 15:06:16.085850270 +0000 @@ -525,3 +525,11 @@ hook_bool_mode_reg_class_t_reg_class_t_f return false; } +/* Generic hook that takes a mode and an unsigned HOST_WIDE_INT and + returns no mode. */ + +opt_machine_mode +hook_optmode_mode_uhwi_none (machine_mode, unsigned HOST_WIDE_INT) +{ + return opt_machine_mode (); +} Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2017-11-08 15:05:36.346297369 +0000 +++ gcc/tree-vect-data-refs.c 2017-11-08 15:06:16.087850270 +0000 @@ -60,20 +60,23 @@ Software Foundation; either version 3, o vect_lanes_optab_supported_p (const char *name, convert_optab optab, tree vectype, unsigned HOST_WIDE_INT count) { - machine_mode mode; - scalar_int_mode array_mode; + machine_mode mode, array_mode; bool limit_p; mode = TYPE_MODE (vectype); - limit_p = !targetm.array_mode_supported_p (mode, count); - if (!int_mode_for_size (count * GET_MODE_BITSIZE (mode), - limit_p).exists (&array_mode)) + if (!targetm.array_mode (mode, count).exists (&array_mode)) { - if (dump_enabled_p ()) - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, - "no array mode for %s[" HOST_WIDE_INT_PRINT_DEC "]\n", - GET_MODE_NAME (mode), count); - return false; + poly_uint64 bits = count * GET_MODE_BITSIZE (mode); + limit_p = !targetm.array_mode_supported_p (mode, count); + if (!int_mode_for_size (bits, limit_p).exists (&array_mode)) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "no array mode for %s[" + HOST_WIDE_INT_PRINT_DEC "]\n", + GET_MODE_NAME (mode), count); + return false; + } } if (convert_optab_handler (optab, array_mode, mode) == CODE_FOR_nothing) Index: gcc/stor-layout.c =================================================================== --- gcc/stor-layout.c 2017-11-08 15:05:36.974386931 +0000 +++ gcc/stor-layout.c 2017-11-08 15:06:16.086850270 +0000 @@ -545,7 +545,8 @@ get_mode_alignment (machine_mode mode) mode_for_array (tree elem_type, tree size) { tree elem_size; - unsigned HOST_WIDE_INT int_size, int_elem_size; + poly_uint64 int_size, int_elem_size; + unsigned HOST_WIDE_INT num_elems; bool limit_p; /* One-element arrays get the component type's mode. */ @@ -554,14 +555,16 @@ mode_for_array (tree elem_type, tree siz return TYPE_MODE (elem_type); limit_p = true; - if (tree_fits_uhwi_p (size) && tree_fits_uhwi_p (elem_size)) + if (poly_int_tree_p (size, &int_size) + && poly_int_tree_p (elem_size, &int_elem_size) + && may_ne (int_elem_size, 0U) + && constant_multiple_p (int_size, int_elem_size, &num_elems)) { - int_size = tree_to_uhwi (size); - int_elem_size = tree_to_uhwi (elem_size); - if (int_elem_size > 0 - && int_size % int_elem_size == 0 - && targetm.array_mode_supported_p (TYPE_MODE (elem_type), - int_size / int_elem_size)) + machine_mode elem_mode = TYPE_MODE (elem_type); + machine_mode mode; + if (targetm.array_mode (elem_mode, num_elems).exists (&mode)) + return mode; + if (targetm.array_mode_supported_p (elem_mode, num_elems)) limit_p = false; } return mode_for_size_tree (size, MODE_INT, limit_p).else_blk ();