From patchwork Thu Dec 28 20:54:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 122879 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3906945qgn; Thu, 28 Dec 2017 12:54:22 -0800 (PST) X-Google-Smtp-Source: ACJfBouEPOs+aX6kkjbsYzMZEIaezUWche6kZcAylYoWQj+r/ToD1cpV7c972k9Vb55A+G/PNHOH X-Received: by 10.84.133.67 with SMTP id 61mr33175788plf.20.1514494462759; Thu, 28 Dec 2017 12:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514494462; cv=none; d=google.com; s=arc-20160816; b=ymQVz8rJQbZVO4aDLjn9cvjC3Lqwsd3dxXKwzrfOHySa29dZtutH595z1dsLIMITYo Fc6GAn2Z5j8OC93CCqg0VMLcCqPIRRishtS9to3PkK4hSbV+iXg6MNhCGmSKFLVQGFiK 4u/s5jqgZULRItLX/WoYQYQh8pzdtTN+ewdZOog1bDcXnYhH+4MRPyL78CWNTmALKVuP fKhsjoC2lMqREjfTpCXJYz76LuwGYFgx1p/8I/a4wj5NXKo8icVqEqamd6frZarGOrqW PQMXLUZxq6CIp7XvFMtDQEHJD2E3irZ8IoxDj9Y0Wksiz7PNHFpn70BkCmZcydmLkgq3 FuGg== 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=wLBzOdkdfe+LLH/7BFPy1Iredugg2TdpN+Orw59lPQo=; b=oWnrEJnpocdc3eVtrEdA4siStgP4JEL9Ga+h+xt+yhAE8TskLW5/j3Idlxk8bz9HMy wThL6i+gJwUvu0/rInXRsm66haLqosM9W6YVCzqlsez03xzmlamgI3gXV5O6Tdr2Q57F VkU8HrrDsjeU2IRe7EYqxn3u3v05Ck1WJ5gEk9cHfW/FTzQy6254KRTqd7YK0B0f/PVX wgZ+6JWQRi+fKm6n+xhBss/+kULdfXH0/d9i2ixRiMqAw0kos8vvY/Fk0kFlNLjA7e4+ zjS1Zv1Zc8gMH24zVjGhh47kJbZflz3F0i9XksQeaJB8mmXwOyLgw8h5VwEAXbiunGU1 cpyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L7wmTYpK; spf=pass (google.com: domain of gcc-patches-return-469874-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-469874-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 u1si2914003pgb.392.2017.12.28.12.54.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Dec 2017 12:54:22 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-469874-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=L7wmTYpK; spf=pass (google.com: domain of gcc-patches-return-469874-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-469874-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=vm84HvgLCXMLrL40Of3tsv14Fc/TM zES02sCQA2q7ea6USQhfbwbGRmjYGm4BnbxXyLWGexxeiziUTQRqcPjEhJHmTMeu T+B3FuV5O5OeTADvNLes4gs2870kgfvDfyGnxPQ+PhhiefNHFyevNnzf7M4IfwL1 TEuNJNeUF6A28U= 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=YucpdnP8gplIiXtsDI1RDQ+htU0=; b=L7w mTYpK6h1g1lAaxiSN1MqBqIqk/JM6Uv2hFXklp+U0hiG5Mnu+/PMh1RqO8k3bqUD 5McvAbCN/m3J55zUqh6339yTL9dUcXtuxlTKJ2Cf+YA2QES3sd3IPx2tbXYxsvma VPhUy6i56wzNBAoCks/Alf/47Sbk+kbowhERZ8+4= Received: (qmail 49448 invoked by alias); 28 Dec 2017 20:54:10 -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 49439 invoked by uid 89); 28 Dec 2017 20:54:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f54.google.com Received: from mail-wm0-f54.google.com (HELO mail-wm0-f54.google.com) (74.125.82.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Dec 2017 20:54:08 +0000 Received: by mail-wm0-f54.google.com with SMTP id 64so45387765wme.3 for ; Thu, 28 Dec 2017 12:54:08 -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:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=wLBzOdkdfe+LLH/7BFPy1Iredugg2TdpN+Orw59lPQo=; b=GcTGeLXp5vTjQb++A3CJ7+Y+nY1Ji0hlICUAs0MoaQXsN3MxLQZlzsJUpbhBTT2PIw cHV3VzlyS6Q7i5mI66fipl1UPsYu8N/eZSu1zskV+br6hdBF8Cg1AnRk3sgH/JZ35HQb aLeOErU7FPLIMOpEWP761x95zCHPsaHr8dW214WVEIkWNYa0vKq8zYlGyp+ChxoUjqDH 2f6kt8eXZOpMtypkkt7bNkqyJ1NeOSJu7JcX1xWgSUzhRzokweqY2xJsHmRoEMAq48on mTafMHjbXxThtYZN+pR0aav9uKmlbUOj9v8wbXDw2sEg66viQq1zKJV9BmKPOiPJ9hMp Xn2A== X-Gm-Message-State: AKGB3mIo+alqOsDbdtV5PNwG7Z/dB3ZgUBwFIDcxeu5tfwkCaJYA9w1e 7ofR2fc34ZTXa318TSBTaJn3BBcmOic= X-Received: by 10.28.129.69 with SMTP id c66mr28099631wmd.29.1514494446143; Thu, 28 Dec 2017 12:54:06 -0800 (PST) Received: from localhost ([95.145.138.186]) by smtp.gmail.com with ESMTPSA id m70sm12818055wma.36.2017.12.28.12.54.05 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Dec 2017 12:54:05 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [4/4] Make CONST_VECTOR_ELT handle implicitly-encoded elements References: <874loainn7.fsf@linaro.org> Date: Thu, 28 Dec 2017 20:54:04 +0000 In-Reply-To: <874loainn7.fsf@linaro.org> (Richard Sandiford's message of "Thu, 28 Dec 2017 20:49:16 +0000") Message-ID: <87k1x6h8ur.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This patch makes CONST_VECTOR_ELT handle implicitly-encoded elements, in a similar way to VECTOR_CST_ELT. 2017-12-28 Richard Sandiford gcc/ * rtl.h (CONST_VECTOR_ELT): Redefine to const_vector_elt. (const_vector_encoded_nelts): New function. (CONST_VECTOR_NUNITS): Redefine to use GET_MODE_NUNITS. (const_vector_int_elt, const_vector_elt): Declare. * emit-rtl.c (const_vector_int_elt_1): New function. (const_vector_elt): Likewise. * simplify-rtx.c (simplify_immed_subreg): Avoid taking the address of CONST_VECTOR_ELT. Index: gcc/rtl.h =================================================================== --- gcc/rtl.h 2017-12-22 13:12:00.662528577 +0000 +++ gcc/rtl.h 2017-12-22 13:12:00.834520649 +0000 @@ -1969,7 +1969,7 @@ #define CONST_FIXED_VALUE_LOW(r) \ ((HOST_WIDE_INT) (CONST_FIXED_VALUE (r)->data.low)) /* For a CONST_VECTOR, return element #n. */ -#define CONST_VECTOR_ELT(RTX, N) XCVECEXP (RTX, 0, N, CONST_VECTOR) +#define CONST_VECTOR_ELT(RTX, N) const_vector_elt (RTX, N) #define CONST_VECTOR_NPATTERNS(RTX) \ (RTL_FLAG_CHECK1 ("CONST_VECTOR_NPATTERNS", (RTX), CONST_VECTOR) \ @@ -1987,8 +1987,16 @@ #define CONST_VECTOR_STEPPED_P(RTX) \ #define CONST_VECTOR_ENCODED_ELT(RTX, N) XCVECEXP (RTX, 0, N, CONST_VECTOR) +/* Return the number of elements encoded directly in a CONST_VECTOR. */ + +inline unsigned int +const_vector_encoded_nelts (const_rtx x) +{ + return CONST_VECTOR_NPATTERNS (x) * CONST_VECTOR_NELTS_PER_PATTERN (x); +} + /* For a CONST_VECTOR, return the number of elements in a vector. */ -#define CONST_VECTOR_NUNITS(RTX) XCVECLEN (RTX, 0, CONST_VECTOR) +#define CONST_VECTOR_NUNITS(RTX) GET_MODE_NUNITS (GET_MODE (RTX)) /* For a SUBREG rtx, SUBREG_REG extracts the value we want a subreg of. SUBREG_BYTE extracts the byte-number. */ @@ -3000,6 +3008,8 @@ unwrap_const_vec_duplicate (T x) } /* In emit-rtl.c. */ +extern wide_int const_vector_int_elt (const_rtx, unsigned int); +extern rtx const_vector_elt (const_rtx, unsigned int); extern bool const_vec_series_p_1 (const_rtx, rtx *, rtx *); /* Return true if X is an integer constant vector that contains a linear Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c 2017-12-22 13:11:58.364634475 +0000 +++ gcc/emit-rtl.c 2017-12-22 13:12:00.833520695 +0000 @@ -5862,6 +5862,62 @@ init_emit (void) #endif } +/* Return the value of element I of CONST_VECTOR X as a wide_int. */ + +wide_int +const_vector_int_elt (const_rtx x, unsigned int i) +{ + /* First handle elements that are directly encoded. */ + machine_mode elt_mode = GET_MODE_INNER (GET_MODE (x)); + if (i < (unsigned int) XVECLEN (x, 0)) + return rtx_mode_t (CONST_VECTOR_ENCODED_ELT (x, i), elt_mode); + + /* Identify the pattern that contains element I and work out the index of + the last encoded element for that pattern. */ + unsigned int encoded_nelts = const_vector_encoded_nelts (x); + unsigned int npatterns = CONST_VECTOR_NPATTERNS (x); + unsigned int count = i / npatterns; + unsigned int pattern = i % npatterns; + unsigned int final_i = encoded_nelts - npatterns + pattern; + + /* If there are no steps, the final encoded value is the right one. */ + if (!CONST_VECTOR_STEPPED_P (x)) + return rtx_mode_t (CONST_VECTOR_ENCODED_ELT (x, final_i), elt_mode); + + /* Otherwise work out the value from the last two encoded elements. */ + rtx v1 = CONST_VECTOR_ENCODED_ELT (x, final_i - npatterns); + rtx v2 = CONST_VECTOR_ENCODED_ELT (x, final_i); + wide_int diff = wi::sub (rtx_mode_t (v2, elt_mode), + rtx_mode_t (v1, elt_mode)); + return wi::add (rtx_mode_t (v2, elt_mode), (count - 2) * diff); +} + +/* Return the value of element I of CONST_VECTOR X. */ + +rtx +const_vector_elt (const_rtx x, unsigned int i) +{ + /* First handle elements that are directly encoded. */ + if (i < (unsigned int) XVECLEN (x, 0)) + return CONST_VECTOR_ENCODED_ELT (x, i); + + /* If there are no steps, the final encoded value is the right one. */ + if (!CONST_VECTOR_STEPPED_P (x)) + { + /* Identify the pattern that contains element I and work out the index of + the last encoded element for that pattern. */ + unsigned int encoded_nelts = const_vector_encoded_nelts (x); + unsigned int npatterns = CONST_VECTOR_NPATTERNS (x); + unsigned int pattern = i % npatterns; + unsigned int final_i = encoded_nelts - npatterns + pattern; + return CONST_VECTOR_ENCODED_ELT (x, final_i); + } + + /* Otherwise work out the value from the last two encoded elements. */ + return immed_wide_int_const (const_vector_int_elt (x, i), + GET_MODE_INNER (GET_MODE (x))); +} + /* Return true if X is a valid element for a CONST_VECTOR of the given mode. */ Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-12-22 13:12:00.662528577 +0000 +++ gcc/simplify-rtx.c 2017-12-22 13:12:00.834520649 +0000 @@ -5990,13 +5990,11 @@ simplify_immed_subreg (fixed_size_mode o if (GET_CODE (op) == CONST_VECTOR) { num_elem = CONST_VECTOR_NUNITS (op); - elems = &CONST_VECTOR_ELT (op, 0); elem_bitsize = GET_MODE_UNIT_BITSIZE (innermode); } else { num_elem = 1; - elems = &op; elem_bitsize = max_bitsize; } /* If this asserts, it is too complicated; reducing value_bit may help. */ @@ -6007,7 +6005,9 @@ simplify_immed_subreg (fixed_size_mode o for (elem = 0; elem < num_elem; elem++) { unsigned char * vp; - rtx el = elems[elem]; + rtx el = (GET_CODE (op) == CONST_VECTOR + ? CONST_VECTOR_ELT (op, elem) + : op); /* Vectors are kept in target memory order. (This is probably a mistake.) */