From patchwork Sat Jan 17 02:06:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 43263 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3AC63240BA for ; Sat, 17 Jan 2015 02:07:36 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id k14sf12645424wgh.2 for ; Fri, 16 Jan 2015 18:07:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mailing-list:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:sender :delivered-to:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type:x-original-sender :x-original-authentication-results; bh=nZEEWz6FcWxUqAuIx/0RGUFF4jmnK4Rd+M7ds94fMwc=; b=CsJgsxZnt7z/EM/EuypLjWaE/CLSpzOAFTje13VkN+Tnb1H0/X826Wuz0XDb0aK64T GuQW+lhLDOYsM3C3z0iTuaOu2D5MtxSb/25o1FG0zjTC+4yhTR9+Zhzp8tmLhz9XA+cj d9QC+lMrfbAU3pI/gme9zfKikxv5pF5Qfmikjz0mWSIfIXLsCNE0EPhuHLKpY1Q5srd3 aI3B6AfjPMPyKfmQy/HLz6Op8Mp3Wtn43GzHmGebs3Wi4yNSAM4b8Lm8Kub1K6mpx8YH HLJl7RxFNG7Umit67gdqUKaUvPagkHjWuYaEPpN6Lyp5qUjIk+gn9nOk23Ks9KfjDOg2 jLWw== X-Gm-Message-State: ALoCoQkxV8oC1eolZXRkh58LuXAKVymzx9JyT/cKvVv0HeVnVRKY8fd6BskbLVqeH6c427zJ15/3 X-Received: by 10.112.37.72 with SMTP id w8mr2288237lbj.6.1421460455296; Fri, 16 Jan 2015 18:07:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.39 with SMTP id x7ls438030lax.92.gmail; Fri, 16 Jan 2015 18:07:35 -0800 (PST) X-Received: by 10.112.43.66 with SMTP id u2mr3218690lbl.35.1421460455024; Fri, 16 Jan 2015 18:07:35 -0800 (PST) Received: from mail-la0-x22e.google.com (mail-la0-x22e.google.com. [2a00:1450:4010:c03::22e]) by mx.google.com with ESMTPS id ay3si4548207lbc.17.2015.01.16.18.07.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Jan 2015 18:07:34 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) client-ip=2a00:1450:4010:c03::22e; Received: by mail-la0-f46.google.com with SMTP id s18so956328lam.5 for ; Fri, 16 Jan 2015 18:07:34 -0800 (PST) X-Received: by 10.112.30.71 with SMTP id q7mr18679256lbh.41.1421460454156; Fri, 16 Jan 2015 18:07:34 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp484918lbb; Fri, 16 Jan 2015 18:07:32 -0800 (PST) X-Received: by 10.70.44.66 with SMTP id c2mr27097399pdm.51.1421460452069; Fri, 16 Jan 2015 18:07:32 -0800 (PST) Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 16si7403132pdf.254.2015.01.16.18.07.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jan 2015 18:07:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-389686-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Received: (qmail 27541 invoked by alias); 17 Jan 2015 02:07:18 -0000 Mailing-List: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org Precedence: list 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 26752 invoked by uid 89); 17 Jan 2015 02:07:16 -0000 X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f48.google.com Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 17 Jan 2015 02:07:11 +0000 Received: by mail-pa0-f48.google.com with SMTP id rd3so27616212pab.7 for ; Fri, 16 Jan 2015 18:07:09 -0800 (PST) X-Received: by 10.68.132.103 with SMTP id ot7mr27717809pbb.0.1421460429311; Fri, 16 Jan 2015 18:07:09 -0800 (PST) Received: from [192.168.1.6] ([112.134.156.250]) by mx.google.com with ESMTPSA id z3sm5226929pdp.17.2015.01.16.18.07.06 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 16 Jan 2015 18:07:08 -0800 (PST) Message-ID: <54B9C3C2.2020402@linaro.org> Date: Sat, 17 Jan 2015 13:06:58 +1100 From: Kugan User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Richard Biener , Jakub Jelinek , Jeff Law Subject: [RFC][PATCH 1/3] Free a bit in SSA_NAME to save wrapped information References: <54B9C2EE.4050100@linaro.org> In-Reply-To: <54B9C2EE.4050100@linaro.org> X-IsSubscribed: yes X-Original-Sender: kugan.vivekanandarajah@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c03::22e as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@gcc.gnu.org X-Google-Group-Id: 836684582541 Freeing a spare-bit to store wrapped attribute by going back to representing VR_ANTI_RANGE as [max + 1, min - 1] in SSA_NAME. Thanks, Kugan gcc/ChangeLog: 2015-01-16 Kugan Vivekanandarajah * tree-ssanames.c (set_range_info): Change range info representation and represent VR_ANTI_RANGE as [max + 1, min - 1]. (get_range_info): Likewise. (set_nonzero_bits): Likewise. (duplicate_ssa_name_range_info): Likewise. * tree-ssanames.h (set_range_info): Change prototype. (get_range_info): Likewise. (set_nonzero_bits): Likewise. (duplicate_ssa_name_range_info): Likewise. * tree-vrp.c (remove_range_assertions): Use new representation. (vrp_finalize): Likewise. diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 9c39f65..744dc43 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -200,11 +200,10 @@ make_ssa_name_fn (struct function *fn, tree var, gimple stmt) /* Store range information RANGE_TYPE, MIN, and MAX to tree ssa_name NAME. */ void -set_range_info (tree name, enum value_range_type range_type, +set_range_info (tree name, const wide_int_ref &min, const wide_int_ref &max) { gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); - gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE); range_info_def *ri = SSA_NAME_RANGE_INFO (name); unsigned int precision = TYPE_PRECISION (TREE_TYPE (name)); @@ -219,16 +218,12 @@ set_range_info (tree name, enum value_range_type range_type, ri->set_nonzero_bits (wi::shwi (-1, precision)); } - /* Record the range type. */ - if (SSA_NAME_RANGE_TYPE (name) != range_type) - SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE); - /* Set the values. */ ri->set_min (min); ri->set_max (max); /* If it is a range, try to improve nonzero_bits from the min/max. */ - if (range_type == VR_RANGE) + if (wi::cmp (min, max, TYPE_SIGN (TREE_TYPE (name))) < 0) { wide_int xorv = ri->get_min () ^ ri->get_max (); if (xorv != 0) @@ -248,6 +243,7 @@ get_range_info (const_tree name, wide_int *min, wide_int *max) gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); gcc_assert (min && max); range_info_def *ri = SSA_NAME_RANGE_INFO (name); + value_range_type range_type; /* Return VR_VARYING for SSA_NAMEs with NULL RANGE_INFO or SSA_NAMEs with integral types width > 2 * HOST_BITS_PER_WIDE_INT precision. */ @@ -255,9 +251,22 @@ get_range_info (const_tree name, wide_int *min, wide_int *max) > 2 * HOST_BITS_PER_WIDE_INT)) return VR_VARYING; - *min = ri->get_min (); - *max = ri->get_max (); - return SSA_NAME_RANGE_TYPE (name); + /* If max < min, it is VR_ANTI_RANGE. */ + if (wi::cmp (ri->get_max (), ri->get_min (), TYPE_SIGN (TREE_TYPE (name))) < 0) + { + /* VR_ANTI_RANGE ~[min, max] is encoded as [max + 1, min - 1]. */ + range_type = VR_ANTI_RANGE; + *min = wi::add (ri->get_max (), 1); + *max = wi::sub (ri->get_min (), 1); + } + else + { + /* Otherwise (when min <= max), it is VR_RANGE. */ + range_type = VR_RANGE; + *min = ri->get_min (); + *max = ri->get_max (); + } + return range_type; } /* Change non-zero bits bitmask of NAME. */ @@ -267,7 +276,7 @@ set_nonzero_bits (tree name, const wide_int_ref &mask) { gcc_assert (!POINTER_TYPE_P (TREE_TYPE (name))); if (SSA_NAME_RANGE_INFO (name) == NULL) - set_range_info (name, VR_RANGE, + set_range_info (name, TYPE_MIN_VALUE (TREE_TYPE (name)), TYPE_MAX_VALUE (TREE_TYPE (name))); range_info_def *ri = SSA_NAME_RANGE_INFO (name); @@ -495,7 +504,8 @@ duplicate_ssa_name_ptr_info (tree name, struct ptr_info_def *ptr_info) /* Creates a duplicate of the range_info_def at RANGE_INFO of type RANGE_TYPE for use by the SSA name NAME. */ void -duplicate_ssa_name_range_info (tree name, enum value_range_type range_type, +duplicate_ssa_name_range_info (tree name, + enum value_range_type range_type ATTRIBUTE_UNUSED, struct range_info_def *range_info) { struct range_info_def *new_range_info; @@ -513,8 +523,6 @@ duplicate_ssa_name_range_info (tree name, enum value_range_type range_type, new_range_info = static_cast (ggc_internal_alloc (size)); memcpy (new_range_info, range_info, size); - gcc_assert (range_type == VR_RANGE || range_type == VR_ANTI_RANGE); - SSA_NAME_ANTI_RANGE_P (name) = (range_type == VR_ANTI_RANGE); SSA_NAME_RANGE_INFO (name) = new_range_info; } diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index a7eeb8f..0d4b212 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -68,7 +68,7 @@ struct GTY ((variable_size)) range_info_def { enum value_range_type { VR_UNDEFINED, VR_RANGE, VR_ANTI_RANGE, VR_VARYING }; /* Sets the value range to SSA. */ -extern void set_range_info (tree, enum value_range_type, const wide_int_ref &, +extern void set_range_info (tree, const wide_int_ref &, const wide_int_ref &); /* Gets the value range from SSA. */ extern enum value_range_type get_range_info (const_tree, wide_int *, diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 2e0b158..9b7695d 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -6915,7 +6915,7 @@ remove_range_assertions (void) && all_imm_uses_in_stmt_or_feed_cond (var, stmt, single_pred (bb))) { - set_range_info (var, SSA_NAME_RANGE_TYPE (lhs), + set_range_info (var, SSA_NAME_RANGE_INFO (lhs)->get_min (), SSA_NAME_RANGE_INFO (lhs)->get_max ()); maybe_set_nonzero_bits (bb, var); @@ -10238,12 +10238,35 @@ vrp_finalize (void) || (vr_value[i]->type == VR_UNDEFINED)) continue; - if ((TREE_CODE (vr_value[i]->min) == INTEGER_CST) - && (TREE_CODE (vr_value[i]->max) == INTEGER_CST) - && (vr_value[i]->type == VR_RANGE - || vr_value[i]->type == VR_ANTI_RANGE)) - set_range_info (name, vr_value[i]->type, vr_value[i]->min, - vr_value[i]->max); + if ((TREE_CODE (vr_value[i]->min) == INTEGER_CST) + && (TREE_CODE (vr_value[i]->max) == INTEGER_CST) + && (vr_value[i]->type == VR_RANGE + || vr_value[i]->type == VR_ANTI_RANGE)) + { + if (vr_value[i]->type == VR_RANGE) + set_range_info (name, vr_value[i]->min, vr_value[i]->max); + else if (vr_value[i]->type == VR_ANTI_RANGE) + { + /* VR_ANTI_RANGE + ~[min, max] is encoded compactly as + [max + 1, min - 1] without additional attributes. + When min value > max value, we know that it is + VR_ANTI_RANGE; it is VR_RANGE otherwise. */ + + if (TYPE_UNSIGNED (TREE_TYPE (name)) + && integer_zerop (vr_value[i]->min) + && integer_zerop (vr_value[i]->max)) + /* ~[0,0] anti-range is represented as range. */ + set_range_info (name, + build_int_cst (TREE_TYPE (name), 1), + TYPE_MAXVAL (TREE_TYPE (name))); + else + set_range_info (name, + wi::add (vr_value[i]->max, 1), + wi::sub (vr_value[i]->min, 1)); + } + } + } /* Free allocated memory. */