From patchwork Mon Aug 8 03:36:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 73402 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp3006653qga; Sun, 7 Aug 2016 20:37:47 -0700 (PDT) X-Received: by 10.98.10.157 with SMTP id 29mr136150403pfk.62.1470627466955; Sun, 07 Aug 2016 20:37:46 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id w27si34588786pfi.135.2016.08.07.20.37.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 20:37:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-433435-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; spf=pass (google.com: domain of gcc-patches-return-433435-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-433435-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=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 :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=nChtG/WAQi16mW+IqPZ4n7jktCcadvxN7SWntJZVqOaYlDPrQRMgk UUSdKvV9oNHapLx7AUShvJhbn/+NNuIX+MO3nTvVQoWgGCystb/n3EC2iMh9qJi4 K/t+saq7+G/6OqDtDdzfqRX4xI5YW6gBRFD8ZakuoAdvwxQhud3FGA= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=X9MRTYhp1Bb0Ro7ONPhHstyGA8w=; b=yE2Vo6HoNfpb5MAFSMDh cCVDVXZI46pDHJsVuNKYdS2BsD5Dt7pkGuVXVc/gMQ2uOxKUORbmFqGWoSxLdj01 1IJDByDz32JNSsLnqRhzilt04ERlbJpiVnKE3YDnEH6w5cZFbBe9JgLvYSjemQdz hv1Yk8cVsjr//IbmNzA3jxI= Received: (qmail 39594 invoked by alias); 8 Aug 2016 03:37:33 -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 39580 invoked by uid 89); 8 Aug 2016 03:37:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:kuganv@, U*kuganv, kuganv@linaro.org, kuganvlinaroorg X-HELO: mail-pf0-f178.google.com Received: from mail-pf0-f178.google.com (HELO mail-pf0-f178.google.com) (209.85.192.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 08 Aug 2016 03:37:21 +0000 Received: by mail-pf0-f178.google.com with SMTP id y134so114552406pfg.0 for ; Sun, 07 Aug 2016 20:37:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version; bh=IqYI/WBVdGGmB1o6275KdJx5PZ7iNWJdq2wIvkLR9wE=; b=k/MZUwu8iG7PF/pcuKzxNbyUZ0vC6w5lCzhnKvnTjD5q+tqA5HP5WDXld1QE5dW+T0 f0RzuO172HLq5wgCqftJxIIluKyGan6wQsLWtPqM1g7vsnZvZbBrWjQSOL0+7ImbFOB9 VExpeQlh5LKaZTXOH0URYunwSi60ZjI8T9kjaI4ro/cknYHfE8Q49M9iKXKjmHk6JqtU JNka6EET+Dkc8zMd2HGwB634gQ0veeloyiFj/J1AJsvsxNwwwWq2flqzyMsM1m/ODo5Q h6DZKs6o0vyx0UUWQLBBsy6x4O3eN0l2Djz1OcbhmFftgo651izC1E2sIIB1s5iuiO/n LR4A== X-Gm-Message-State: AEkoouta1krEkMG5SOaavsBK0942e0mqtHi/a6jM80AMANt9rRyMctXfdjG+EpX8lVlpJfEB X-Received: by 10.98.58.73 with SMTP id h70mr156970524pfa.125.1470627439407; Sun, 07 Aug 2016 20:37:19 -0700 (PDT) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id i7sm43639970paf.9.2016.08.07.20.37.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Aug 2016 20:37:18 -0700 (PDT) From: kugan Subject: Set nonnull attribute to ptr_info_def based on VRP To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jeff Law Message-ID: <717fb095-f0a9-6980-ddbd-e755a4fd6457@linaro.org> Date: Mon, 8 Aug 2016 13:36:51 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, This patch tries to add nonnull_p attribute to ptr_info_def. As it stands, range_info_def is bigger in size than ptr_info_def. Therefore adding nonnull_p should not change the size. I am setting this based on the VRP analysis. Right there is no uses for this. But the idea is, this can be used in IPA-VRP such that redundant check for NULL can be eliminated. Bootstrapped and regression tested on x86_64-linux-gnu. Is this OK for trunk. Thanks, Kugan gcc/ChangeLog: 2016-08-08 Kugan Vivekanandarajah * tree-ssanames.c (set_ptr_nonnull): New. (get_ptr_nonnull): Likewise. * tree-ssanames.h (struct ptr_info_def): Add nonnull_p attribute. * tree-vrp.c (vrp_finalize): Call set_ptr_nonnull. diff --git a/gcc/tree-ssanames.c b/gcc/tree-ssanames.c index 91a8f97..19c9027 100644 --- a/gcc/tree-ssanames.c +++ b/gcc/tree-ssanames.c @@ -374,6 +374,27 @@ get_range_info (const_tree name, wide_int *min, wide_int *max) return SSA_NAME_RANGE_TYPE (name); } +/* Set nonnull attribute to pointer NAME. */ + +void +set_ptr_nonnull (tree name, bool nonnull_p) +{ + gcc_assert (POINTER_TYPE_P (TREE_TYPE (name))); + struct ptr_info_def *pi = get_ptr_info (name); + pi->nonnull_p = nonnull_p;; +} + +/* Return nonnull attribute of pointer NAME. */ +bool +get_ptr_nonnull (tree name) +{ + gcc_assert (POINTER_TYPE_P (TREE_TYPE (name))); + struct ptr_info_def *pi = SSA_NAME_PTR_INFO (name); + if (pi == NULL) + return false; + return pi->nonnull_p; +} + /* Change non-zero bits bitmask of NAME. */ void diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h index c81b1a1..6e34433 100644 --- a/gcc/tree-ssanames.h +++ b/gcc/tree-ssanames.h @@ -43,6 +43,9 @@ struct GTY(()) ptr_info_def above alignment. Access only through the same helper functions as align above. */ unsigned int misalign; + /* When this pointer is knonw to be nnonnull this would be true otherwise + false. */ + bool nonnull_p; }; /* Value range information for SSA_NAMEs representing non-pointer variables. */ @@ -89,6 +92,8 @@ extern void set_ptr_info_alignment (struct ptr_info_def *, unsigned int, extern void adjust_ptr_info_misalignment (struct ptr_info_def *, unsigned int); extern struct ptr_info_def *get_ptr_info (tree); +extern void set_ptr_nonnull (tree name, bool nonnull_p); +extern bool get_ptr_nonnull (tree name); extern tree copy_ssa_name_fn (struct function *, tree, gimple *); extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *); diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 7c7ad91..40c4d48 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -10352,18 +10352,24 @@ vrp_finalize (bool warn_array_bounds_p) { tree name = ssa_name (i); - if (!name - || POINTER_TYPE_P (TREE_TYPE (name)) - || (vr_value[i]->type == VR_VARYING) - || (vr_value[i]->type == VR_UNDEFINED)) - continue; + if (!name + || (vr_value[i]->type == VR_VARYING) + || (vr_value[i]->type == VR_UNDEFINED) + || (TREE_CODE (vr_value[i]->min) != INTEGER_CST) + || (TREE_CODE (vr_value[i]->max) != INTEGER_CST)) + 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 (POINTER_TYPE_P (TREE_TYPE (name)) + && ((vr_value[i]->type == VR_RANGE + && range_includes_zero_p (vr_value[i]->min, + vr_value[i]->max) == 0) + || (vr_value[i]->type == VR_ANTI_RANGE + && range_includes_zero_p (vr_value[i]->min, + vr_value[i]->max) == 1))) + set_ptr_nonnull (name, true); + else if (!POINTER_TYPE_P (TREE_TYPE (name))) + set_range_info (name, vr_value[i]->type, vr_value[i]->min, + vr_value[i]->max); } substitute_and_fold (op_with_constant_singleton_value_range,