From patchwork Wed Dec 4 00:03:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 296363 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5F12B2C00A0 for ; Wed, 4 Dec 2013 11:03:34 +1100 (EST) 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=HLx4pluCmZmTcpAn lKMdAsXJhleZ2O7gUIh7k54hyFBKAMeN8Ce1bouQqs8wublLOVIRSzvt4DKr4Tvd phmjT5B+gVR4LLzEs9Gh/wf2RnzMoA8fg4xwtg+vq5oKZpOI5UOaq1nLrCj6hCPQ A7RPM/xVgw8Pt0hovTWeR5VpA+c= 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=zyWYt20CSrG7Lwrm9CxtJS kBtKs=; b=OIUS2S9w6YJ83vzrdh5PVf6mCxXcrX4/Xxg1HCqDydGLO983KPBU9w HBmsZylZx7B27IQNMzI09+Dq5v8sTwGJ93OAdBmjiHcrOpgTxpb/F7T+A/z+L4Qj RBYzGGev67h3pLrNX9VqPFjIBP97ndpOK85pySi0wA8kjz3RXQSNE= Received: (qmail 13573 invoked by alias); 4 Dec 2013 00:03:25 -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 13563 invoked by uid 89); 4 Dec 2013 00:03:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-wi0-f172.google.com Received: from Unknown (HELO mail-wi0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 04 Dec 2013 00:03:23 +0000 Received: by mail-wi0-f172.google.com with SMTP id en1so7436025wid.5 for ; Tue, 03 Dec 2013 16:03:14 -0800 (PST) X-Received: by 10.180.107.193 with SMTP id he1mr4774645wib.50.1386115394375; Tue, 03 Dec 2013 16:03:14 -0800 (PST) Received: from localhost ([2.28.235.199]) by mx.google.com with ESMTPSA id ll10sm1597625wic.9.2013.12.03.16.03.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Dec 2013 16:03:13 -0800 (PST) From: Richard Sandiford To: Richard Biener Mail-Followup-To: Richard Biener , GCC Patches , Kenneth Zadeck , Mike Stump , rdsandiford@googlemail.com Cc: GCC Patches , Kenneth Zadeck , Mike Stump Subject: Re: Add TREE_INT_CST_OFFSET_NUNITS References: <8738me6x8y.fsf@talisman.default> <8738mbfjnn.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> Date: Wed, 04 Dec 2013 00:03:13 +0000 In-Reply-To: (Richard Biener's message of "Mon, 2 Dec 2013 14:53:38 +0100") Message-ID: <87a9ghcwji.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Richard Biener writes: >>> Looking at the implementation it seems it would also work with >>> >>> return MIN (TREE_INT_CST_EXT_NUNITS (m_t), N / HOST_BITS_PER_WIDE_INT); >> >> Yeah, the MIN in the patch was probably bogus sorry. It only works >> if we can assume that no bitsizetype will have ADDR_MAX_PRECISION >> significant (non-sign) bits -- in particular that there's no such thing as >> an all-1s _unsigned_ bitsizetype. That might be true in practice given >> the way we use offsets, but it isn't safe to generalise that to all N. >> >> A safer form would be: >> >> if (ext_len > OFFSET_INT_ELTS) >> TREE_INT_CST_OFFSET_NUNITS (t) = len; >> else >> TREE_INT_CST_OFFSET_NUNITS (t) = ext_len; >> >> The reason the general form doesn't work for all N is because of the >> compressed representation. E.g. the example I gave a while ago about >> a 256-bit all-1s unsigned number being { -1 } as a 256-bit number and >> { -1, -1, -1, -1, 0 } as a 257+-bit number. >> >> But the point of the patch is to avoid any runtime checks here, >> so the TYPE_PRECISION case is never actually used now. I just kept >> it around for completeness, since we'd been using it successfully so far. >> I can put in a gcc_unreachable if you prefer. > > Yeah, I'd prefer a gcc_unreachable and a comment. OK, how about this version? Tested on x86_64-linux-gnu. Thanks, Richard Index: gcc/ChangeLog.wide-int =================================================================== --- gcc/ChangeLog.wide-int 2013-12-03 23:55:26.142873345 +0000 +++ gcc/ChangeLog.wide-int 2013-12-03 23:59:18.823744425 +0000 @@ -617,6 +617,7 @@ (TREE_INT_CST_HIGH): Delete. (TREE_INT_CST_NUNITS): New. (TREE_INT_CST_EXT_NUNITS): Likewise. + (TREE_INT_CST_OFFSET_NUNITS): Likewise. (TREE_INT_CST_ELT): Likewise. (INT_CST_LT): Use wide-int interfaces. (INT_CST_LE): New. Index: gcc/tree-core.h =================================================================== --- gcc/tree-core.h 2013-12-03 23:55:26.142873345 +0000 +++ gcc/tree-core.h 2013-12-04 00:02:22.910222722 +0000 @@ -764,11 +764,17 @@ struct GTY(()) tree_base { struct { /* The number of HOST_WIDE_INTs if the INTEGER_CST is accessed in its native precision. */ - unsigned short unextended; + unsigned char unextended; /* The number of HOST_WIDE_INTs if the INTEGER_CST is extended to wider precisions based on its TYPE_SIGN. */ - unsigned short extended; + unsigned char extended; + + /* The number of HOST_WIDE_INTs if the INTEGER_CST is accessed in + offset_int precision, with smaller integers being extended + according to their TYPE_SIGN. This is equal to one of the two + fields above but is cached for speed. */ + unsigned char offset; } int_length; /* VEC length. This field is only used with TREE_VEC. */ Index: gcc/tree.c =================================================================== --- gcc/tree.c 2013-12-03 23:55:26.142873345 +0000 +++ gcc/tree.c 2013-12-03 23:59:18.821744409 +0000 @@ -1285,6 +1285,7 @@ wide_int_to_tree (tree type, const wide_ /* Make sure no one is clobbering the shared constant. */ gcc_checking_assert (TREE_TYPE (t) == type && TREE_INT_CST_NUNITS (t) == 1 + && TREE_INT_CST_OFFSET_NUNITS (t) == 1 && TREE_INT_CST_EXT_NUNITS (t) == 1 && TREE_INT_CST_ELT (t, 0) == hwi); else @@ -1964,6 +1965,13 @@ make_int_cst_stat (int len, int ext_len TREE_SET_CODE (t, INTEGER_CST); TREE_INT_CST_NUNITS (t) = len; TREE_INT_CST_EXT_NUNITS (t) = ext_len; + /* to_offset can only be applied to trees that are offset_int-sized + or smaller. EXT_LEN is correct if it fits, otherwise the constant + must be exactly the precision of offset_int and so LEN is correct. */ + if (ext_len <= OFFSET_INT_ELTS) + TREE_INT_CST_OFFSET_NUNITS (t) = ext_len; + else + TREE_INT_CST_OFFSET_NUNITS (t) = len; TREE_CONSTANT (t) = 1; Index: gcc/tree.h =================================================================== --- gcc/tree.h 2013-12-03 23:55:26.142873345 +0000 +++ gcc/tree.h 2013-12-04 00:01:48.258944485 +0000 @@ -907,6 +907,8 @@ #define TREE_INT_CST_NUNITS(NODE) \ (INTEGER_CST_CHECK (NODE)->base.u.int_length.unextended) #define TREE_INT_CST_EXT_NUNITS(NODE) \ (INTEGER_CST_CHECK (NODE)->base.u.int_length.extended) +#define TREE_INT_CST_OFFSET_NUNITS(NODE) \ + (INTEGER_CST_CHECK (NODE)->base.u.int_length.offset) #define TREE_INT_CST_ELT(NODE, I) TREE_INT_CST_ELT_CHECK (NODE, I) #define TREE_INT_CST_LOW(NODE) \ ((unsigned HOST_WIDE_INT) TREE_INT_CST_ELT (NODE, 0)) @@ -4623,11 +4625,15 @@ wi::extended_tree ::get_val () const inline unsigned int wi::extended_tree ::get_len () const { - if (N == MAX_BITSIZE_MODE_ANY_INT - || N > TYPE_PRECISION (TREE_TYPE (m_t))) + if (N == ADDR_MAX_PRECISION) + return TREE_INT_CST_OFFSET_NUNITS (m_t); + else if (N == MAX_BITSIZE_MODE_ANY_INT) return TREE_INT_CST_EXT_NUNITS (m_t); else - return TREE_INT_CST_NUNITS (m_t); + /* This class is designed to be used for specific output precisions + and needs to be as fast as possible, so there is no fallback for + other casees. */ + gcc_unreachable (); } namespace wi Index: gcc/wide-int.h =================================================================== --- gcc/wide-int.h 2013-12-03 23:59:08.135658583 +0000 +++ gcc/wide-int.h 2013-12-03 23:59:18.823744425 +0000 @@ -256,6 +256,9 @@ #define ADDR_MAX_BITSIZE 64 #define ADDR_MAX_PRECISION \ ((ADDR_MAX_BITSIZE + 4 + HOST_BITS_PER_WIDE_INT - 1) & ~(HOST_BITS_PER_WIDE_INT - 1)) +/* The number of HWIs needed to store an offset_int. */ +#define OFFSET_INT_ELTS (ADDR_MAX_PRECISION / HOST_BITS_PER_WIDE_INT) + /* The type of result produced by a binary operation on types T1 and T2. Defined purely for brevity. */ #define WI_BINARY_RESULT(T1, T2) \