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: 430085 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CF4CC140216 for ; Sat, 17 Jan 2015 13:07:26 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=enicBgjJwNaUSBaYR ES+v9dYhF+62YhqQtmzqMO9yXnS0FTB5GMoQlxZjvzo7XX8uVgZ2OOd9FpCOkYqC 2LNqaKrC78d9ol4xnlx9hSmP0Ptampgj4QLIy8bKh6w0eQO2EpBZqZGIrOCoZ63w x2ayy9J80SELIqG4M/KcSUBTYo= 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 :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=T1eoj1UoKYMJNFdLwj9XthL S9cM=; b=rEUTxw/q3THw9xZZiomyn88R8plj7ko6jAp27HMrR2S6JMLOua0lfU1 AzAmgbXQNDvZfj9ZFBRz/RfeT5dqHTlNrghfOqUcIxRbVOqss0ijU4fJf2uE+1qO ctLLO4S6D7RB+gYHCyhHzJRBByPgmfYNV6AS+51ykAEbf7AADwlc= Received: (qmail 27541 invoked by alias); 17 Jan 2015 02:07:18 -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 26752 invoked by uid 89); 17 Jan 2015 02:07:16 -0000 Authentication-Results: sourceware.org; auth=none 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-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type; bh=nZEEWz6FcWxUqAuIx/0RGUFF4jmnK4Rd+M7ds94fMwc=; b=D4nIcAAb0cCIcnYy3mfGObyCKUMrcLIJLEK89dNbi9SKwFOmISc7FFbxWicRyEyNBJ KBDGyH9qH6by7at6Tg7Cnd97xiPoUtzETmirdlYtIYdeo7XAwMC0yddfuNqBzgs2aD5J /1P9ni9ZY7VJezuqkBFaHdaFOCY9rG/FKnFouLLFQ/Z3AmwHEndmpyuEfA2eJnBiNXJA O8lE5VcP2vUsJuaqREW6S03EzQ2QTSJKh1hfVP3vb9DW41meDvqPkcSwXAebySSoh8MP btSwyYJByl/ln+SznY52zBYqQK/JqajhVCCoLgK/3pFZhUXQE1auQMTVkRhF2kwk64hh NY+g== X-Gm-Message-State: ALoCoQnbuifcVxBlwUOOwAwG0q+tJNxafkI5jl6J5KPcq2jQE+n6yPWO22gpwlo+0jLQfrQYfriH 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 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. */