From patchwork Mon Oct 23 11:18:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 116685 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4524815qgn; Mon, 23 Oct 2017 04:19:16 -0700 (PDT) X-Received: by 10.99.67.71 with SMTP id q68mr11568808pga.163.1508757556820; Mon, 23 Oct 2017 04:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508757556; cv=none; d=google.com; s=arc-20160816; b=seII1rPb21lOWhgCXd5nyEaUAR+QCXEOm1J7IhvEQwe+P21THfLGlPiVvuqhTxvBdy FnK/3eyQJ6pTq2f2tnhpREciC3MO8RTC2tH1KpHOS+aHaSmX27b5JwGvqRFEAG5UHtYG i1AnW5VtinC0aj49wREoFzP/YJT0APgQGwi1H0UNDPErNrHPM8WmikB4GZJ16EuRzoFb PiQzD7CrHJ6v4V79Aq9Cvj+qlDiRhJvZEnpRhtFx+6a9WAGqR5Ydrg4JBZ3qHbLffn+F pwIyQtp22MIvM3SWxgrFSgYRITbMBKWPMF9gBhzCxAyd5U8RNAGIqvn9D0HUBYOeF86E kBLw== 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: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=gJORoq3otE/tGLnU/BkzVjXlzCtx0d7K6v8B6hmcnuA=; b=QWLdC8PV8+26I3lsM5g4GJSUh2RC5/aBITqqQpeRwuJ9lPf9+bZwYh48GvHVTDZMzc Udefd3L49OtZVZZdZEJIOk3Mlxx9RPZy3/cPoBeSmGPt1/d/+YYllCdSxi9SwTqePcng TbXtMVNaxKOKGwG52k/zEfVYgM3/XWyiBxDgAuutlQF26tRbAYO6yyvacgRAb8B/fbx0 lOkXCbp6G/A5+u4pvsHlyZ/37WUstTouVEDhNuSAcg+d6Xkm9Ug5UL7nazWdgMGWA0gm zYUdLLgN8aOprulelSvoAHLwqk25e3ORQLuCQ/J5l/I5GBr6N/ey5uA3m8jBNNRF2xIx qtAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nAiVvsKr; spf=pass (google.com: domain of gcc-patches-return-464729-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464729-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 m13si4775532pgs.20.2017.10.23.04.19.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Oct 2017 04:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-464729-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=nAiVvsKr; spf=pass (google.com: domain of gcc-patches-return-464729-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-464729-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:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=uCDcvItKPk6jX5qJnY55w8BxWsxps i8T9j1wpxMMtKMKfbRGMlF5chwJfcb4rmlYu78+zkXUdpDx4btjd4JGLLIBfPqjj HFHRnr3IwvxwmSTi24bAbt1JjVxwkC7Dc+H0bo4vu/oyLpS8k+qXhgugX1nBU9GV 4HvQQPqqKd1KZU= 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=BGgHvUtJ8iWAGFfMq36CFNY+Bwc=; b=nAi VvsKr2dxiOU8mIlojjlMEisK7D2XXAhOb/4bnCqXf7a2f8U2JPygImLqV45TNfb2 2UdmQRrZhepgZBUTaVV7KyZ8qHujcvkTxQPylNyCuk/aKEBUs+KNZIJe+Sqcxf7k QEyCyi8+VetmN9k48AecZJoNAOYVBtcgxncG5qJ0= Received: (qmail 25424 invoked by alias); 23 Oct 2017 11:19:02 -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 22631 invoked by uid 89); 23 Oct 2017 11:19:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-14.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f47.google.com Received: from mail-wm0-f47.google.com (HELO mail-wm0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Oct 2017 11:18:58 +0000 Received: by mail-wm0-f47.google.com with SMTP id u138so8786432wmu.5 for ; Mon, 23 Oct 2017 04:18:58 -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=gJORoq3otE/tGLnU/BkzVjXlzCtx0d7K6v8B6hmcnuA=; b=ZOgy6Wx79xBMDlhfRSSJ+Ms4EDB0GEmy9Fwj2uL4G+TByvuhx27qxif3zPm88UUtTo 72Pl7j8eLIg2Tq5oa033vHrQWp6w68YsrKfDSZqcIHUkowbpa2Rya+w2hV3de12nKP0/ Tl/rmiTfKtgEb3xX0gNAnSBA1Mt1PvcTYDel3f2/CDGqcdaoEZ+s38Gov4K5WMp31g4r jzQKF7C71vT5WtTtFIa/1kI8PecOgYdDyXsSA38+Aw5jpUXtuKcclEBmARkN8sQ7bamr pSW7NM/W4sK82xZt1fzPVcLDbt9/RZdUbu18H5Z12s4w5UXZ1g21XmmoBxBZgpGhbERb OC2Q== X-Gm-Message-State: AMCzsaVa9oNmNAB+38UjkPBg1SDm+JYKex7ThaF0pJueqYl7fw7eg20v gBLRYieMeHz4YZ5LFFnSbJpExqdhY7A= X-Google-Smtp-Source: ABhQp+Tp+h83N+2sAKtY4R7L8i7LRzh6J/g/Dv/yCszqNbPfVKdH/IIEYcOGKcfYyf0Ck2baKY3E4g== X-Received: by 10.28.24.7 with SMTP id 7mr5606047wmy.78.1508757536459; Mon, 23 Oct 2017 04:18:56 -0700 (PDT) Received: from localhost ([2.26.27.199]) by smtp.gmail.com with ESMTPSA id v5sm4977262wrf.29.2017.10.23.04.18.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Oct 2017 04:18:55 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [03/nn] Allow vector CONSTs References: <87wp3mxgir.fsf@linaro.org> Date: Mon, 23 Oct 2017 12:18:53 +0100 In-Reply-To: <87wp3mxgir.fsf@linaro.org> (Richard Sandiford's message of "Mon, 23 Oct 2017 12:14:36 +0100") Message-ID: <87k1zmxgbm.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch allows (const ...) wrappers to be used for rtx vector constants, as an alternative to const_vector. This is useful for SVE, where the number of elements isn't known until runtime. It could also be useful in future for fixed-length vectors, to reduce the amount of memory needed to represent simple constants with high element counts. However, one nice thing about keeping it restricted to variable-length vectors is that there is never any need to handle combinations of (const ...) and CONST_VECTOR. 2017-10-23 Richard Sandiford Alan Hayward David Sherwood gcc/ * doc/rtl.texi (const): Update description of address constants. Say that vector constants are allowed too. * common.md (E, F): Use CONSTANT_P instead of checking for CONST_VECTOR. * emit-rtl.c (gen_lowpart_common): Use const_vec_p instead of checking for CONST_VECTOR. * expmed.c (make_tree): Use build_vector_from_val for a CONST VEC_DUPLICATE. * expr.c (expand_expr_real_2): Check for vector modes instead of checking for CONST_VECTOR. * rtl.h (const_vec_p): New function. (const_vec_duplicate_p): Check for a CONST VEC_DUPLICATE. (unwrap_const_vec_duplicate): Handle them here too. Index: gcc/doc/rtl.texi =================================================================== --- gcc/doc/rtl.texi 2017-10-23 11:41:22.176892260 +0100 +++ gcc/doc/rtl.texi 2017-10-23 11:41:39.185050437 +0100 @@ -1667,14 +1667,17 @@ Usually that is the only mode for which @findex const @item (const:@var{m} @var{exp}) -Represents a constant that is the result of an assembly-time -arithmetic computation. The operand, @var{exp}, is an expression that -contains only constants (@code{const_int}, @code{symbol_ref} and -@code{label_ref} expressions) combined with @code{plus} and -@code{minus}. However, not all combinations are valid, since the -assembler cannot do arbitrary arithmetic on relocatable symbols. +Wraps an rtx computation @var{exp} whose inputs and result do not +change during the execution of a thread. There are two valid uses. +The first is to represent a global or thread-local address calculation. +In this case @var{exp} should contain @code{const_int}, +@code{symbol_ref}, @code{label_ref} or @code{unspec} expressions, +combined with @code{plus} and @code{minus}. Any such @code{unspec}s +are target-specific and typically represent some form of relocation +operator. @var{m} should be a valid address mode. -@var{m} should be @code{Pmode}. +The second use of @code{const} is to wrap a vector operation. +In this case @var{exp} must be a @code{vec_duplicate} expression. @findex high @item (high:@var{m} @var{exp}) Index: gcc/common.md =================================================================== --- gcc/common.md 2017-10-23 11:40:11.431285821 +0100 +++ gcc/common.md 2017-10-23 11:41:39.184050436 +0100 @@ -80,14 +80,14 @@ (define_constraint "n" (define_constraint "E" "Matches a floating-point constant." (ior (match_test "CONST_DOUBLE_AS_FLOAT_P (op)") - (match_test "GET_CODE (op) == CONST_VECTOR + (match_test "CONSTANT_P (op) && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT"))) ;; There is no longer a distinction between "E" and "F". (define_constraint "F" "Matches a floating-point constant." (ior (match_test "CONST_DOUBLE_AS_FLOAT_P (op)") - (match_test "GET_CODE (op) == CONST_VECTOR + (match_test "CONSTANT_P (op) && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT"))) (define_constraint "X" Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c 2017-10-23 11:41:32.369050264 +0100 +++ gcc/emit-rtl.c 2017-10-23 11:41:39.186050437 +0100 @@ -1470,7 +1470,7 @@ gen_lowpart_common (machine_mode mode, r return gen_rtx_fmt_e (GET_CODE (x), int_mode, XEXP (x, 0)); } else if (GET_CODE (x) == SUBREG || REG_P (x) - || GET_CODE (x) == CONCAT || GET_CODE (x) == CONST_VECTOR + || GET_CODE (x) == CONCAT || const_vec_p (x) || CONST_DOUBLE_AS_FLOAT_P (x) || CONST_SCALAR_INT_P (x)) return lowpart_subreg (mode, x, innermode); Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2017-10-23 11:41:25.541909864 +0100 +++ gcc/expmed.c 2017-10-23 11:41:39.186050437 +0100 @@ -5246,7 +5246,15 @@ make_tree (tree type, rtx x) return fold_convert (type, make_tree (t, XEXP (x, 0))); case CONST: - return make_tree (type, XEXP (x, 0)); + { + rtx op = XEXP (x, 0); + if (GET_CODE (op) == VEC_DUPLICATE) + { + tree elt_tree = make_tree (TREE_TYPE (type), XEXP (op, 0)); + return build_vector_from_val (type, elt_tree); + } + return make_tree (type, op); + } case SYMBOL_REF: t = SYMBOL_REF_DECL (x); Index: gcc/expr.c =================================================================== --- gcc/expr.c 2017-10-23 11:41:24.408308073 +0100 +++ gcc/expr.c 2017-10-23 11:41:39.187050437 +0100 @@ -9429,7 +9429,7 @@ #define REDUCE_BIT_FIELD(expr) (reduce_b /* Careful here: if the target doesn't support integral vector modes, a constant selection vector could wind up smooshed into a normal integral constant. */ - if (CONSTANT_P (op2) && GET_CODE (op2) != CONST_VECTOR) + if (CONSTANT_P (op2) && !VECTOR_MODE_P (GET_MODE (op2))) { tree sel_type = TREE_TYPE (treeop2); machine_mode vmode Index: gcc/rtl.h =================================================================== --- gcc/rtl.h 2017-10-23 11:41:36.307050364 +0100 +++ gcc/rtl.h 2017-10-23 11:41:39.188050437 +0100 @@ -2749,12 +2749,22 @@ extern rtx shallow_copy_rtx (const_rtx C extern int rtx_equal_p (const_rtx, const_rtx); extern bool rtvec_all_equal_p (const_rtvec); +/* Return true if X is some form of vector constant. */ + +inline bool +const_vec_p (const_rtx x) +{ + return VECTOR_MODE_P (GET_MODE (x)) && CONSTANT_P (x); +} + /* Return true if X is a vector constant with a duplicated element value. */ inline bool const_vec_duplicate_p (const_rtx x) { - return GET_CODE (x) == CONST_VECTOR && rtvec_all_equal_p (XVEC (x, 0)); + return ((GET_CODE (x) == CONST_VECTOR && rtvec_all_equal_p (XVEC (x, 0))) + || (GET_CODE (x) == CONST + && GET_CODE (XEXP (x, 0)) == VEC_DUPLICATE)); } /* Return true if X is a vector constant with a duplicated element value. @@ -2764,11 +2774,16 @@ const_vec_duplicate_p (const_rtx x) inline bool const_vec_duplicate_p (T x, T *elt) { - if (const_vec_duplicate_p (x)) + if (GET_CODE (x) == CONST_VECTOR && rtvec_all_equal_p (XVEC (x, 0))) { *elt = CONST_VECTOR_ELT (x, 0); return true; } + if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == VEC_DUPLICATE) + { + *elt = XEXP (XEXP (x, 0), 0); + return true; + } return false; } @@ -2794,8 +2809,10 @@ vec_duplicate_p (T x, T *elt) inline T unwrap_const_vec_duplicate (T x) { - if (const_vec_duplicate_p (x)) - x = CONST_VECTOR_ELT (x, 0); + if (GET_CODE (x) == CONST_VECTOR && rtvec_all_equal_p (XVEC (x, 0))) + return CONST_VECTOR_ELT (x, 0); + if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == VEC_DUPLICATE) + return XEXP (XEXP (x, 0), 0); return x; }