From patchwork Wed Oct 12 06:54:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 77533 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp324759qge; Tue, 11 Oct 2016 23:54:33 -0700 (PDT) X-Received: by 10.99.51.15 with SMTP id z15mr6800428pgz.41.1476255272980; Tue, 11 Oct 2016 23:54:32 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h5si6443459pal.201.2016.10.11.23.54.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Oct 2016 23:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-438286-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-438286-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-438286-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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=f/3Xjw+q0nlj4mgxo 4m4BMGb66NI4z/0fUlyiFes62j0fInV1qFFV3+RJq+0Mh6QcNQmnaWeGtXdyItWj sW2NthE3oGaSv7tGokDnVkzdYhf7XMLh+N06Te34eMDsfmoRimeYxKU6sT+/U2pW p0rE4uaRwtWgKKeGYAQO9l/5Aw= 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 :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=6V1yTmiEOc/0os3UgoZinBG wYVk=; b=okiBHGqxs4m6KQl0rjZAjwvPqGO/wZfC7tgeKfv88RzHmPLKMm18stD X8q1RAzVv039+ViZV2YERAt3Aub6hCKhSGeoXF0Svp29cNL2z7ddb6KCwIUQLs0m 9bHsvKnvHDCS0RHhJy4zXqYOGW+KfP6gEuZ+WG2sMWqI72rOrXIs= Received: (qmail 48745 invoked by alias); 12 Oct 2016 06:54:17 -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 48026 invoked by uid 89); 12 Oct 2016 06:54:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=no version=3.3.2 spammy=1668, 7, 16687, noclone, get_ptr_nonnull X-HELO: mail-pf0-f172.google.com Received: from mail-pf0-f172.google.com (HELO mail-pf0-f172.google.com) (209.85.192.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Oct 2016 06:54:07 +0000 Received: by mail-pf0-f172.google.com with SMTP id s8so14306417pfj.2 for ; Tue, 11 Oct 2016 23:54:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=Md7d3aZnmSagWjfEsyw4lBporRd47gFGlnoewCK3QrA=; b=Su+OU4ovkoI7LKOzoufgJm00Qel8F6cwGB69OiEVP1RyxXJjGd3jKUsyoWpLhYsSJm iuB5zpZNUICq2N9l2WaNeIracC6bCJ9M6OT2Dpq28EFScqRfnRg04ovO2iUC1tXifN6A v0G6c0dq0Atrx+i2YA8vKCRKwrCLDd/kDGyfTCJlp65tNRGp95eHH1kTzNJ9HrkhKyAe ReX4XduyZ/FzXAWhn/uiszD5wmZH1ol7uvyNQVCCQ6hgHFW4KZ5VLhsY6vjJgXTzKeLl ixacCu54tIjB3duxKgFPJv9yD5XyMRmmrz0+LHenLrEIgE4i8AcOidQujrU85Eq9zlLO d/Yw== X-Gm-Message-State: AA6/9RlexQEcn8Q+jX8xpGscVeyd0bChH6YgkbI+m7DuTpElK8Jhn4DWPcRxWG3kTSNsX+ci X-Received: by 10.98.223.145 with SMTP id d17mr2929857pfl.82.1476255245350; Tue, 11 Oct 2016 23:54:05 -0700 (PDT) Received: from [10.1.1.7] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id e6sm8935193pfb.57.2016.10.11.23.54.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Oct 2016 23:54:04 -0700 (PDT) Subject: [ipa-vrp] Use get/set_ptr_nonnull in ipa-vrp To: "gcc-patches@gcc.gnu.org" , Richard Biener , Jeff Law , Jan Hubicka , Martin Jambor References: <717fb095-f0a9-6980-ddbd-e755a4fd6457@linaro.org> From: kugan Message-ID: <867817be-aaed-7e0f-9d77-ba9e0b639f48@linaro.org> Date: Wed, 12 Oct 2016 17:54:00 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <717fb095-f0a9-6980-ddbd-e755a4fd6457@linaro.org> X-IsSubscribed: yes Hi, This patch uses the get/set_ptr_nonnull so that ipa-vrp also propagates nonnull ranges for pinter. Bootstrapped and regression tested this with other patched without any new regressions on x86_64-linux-gnu. Is this OK for trunk? Thanks, Kugan gcc/ChangeLog: 2016-10-12 Kugan Vivekanandarajah * ipa-prop.c (ipa_compute_jump_functions_for_edge): Set value range for pointer type too. (ipcp_update_vr): set_ptr_nonnull for pointer. gcc/testsuite/ChangeLog: 2016-10-12 Kugan Vivekanandarajah * gcc.dg/ipa/vrp4.c: New test. >From f773226855968cc652fa6f2b2d9c70d2a5d7acdb Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Wed, 12 Oct 2016 13:54:34 +1100 Subject: [PATCH 2/3] Set-nonnull-range-for-pointer-type --- gcc/ipa-prop.c | 57 +++++++++++++++++++++++++++++------------ gcc/testsuite/gcc.dg/ipa/vrp4.c | 27 +++++++++++++++++++ 2 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/vrp4.c diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index a1d7619..353b638 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1668,7 +1668,22 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, useful_context = true; } - if (!POINTER_TYPE_P (TREE_TYPE (arg))) + if (POINTER_TYPE_P (TREE_TYPE (arg))) + { + if (TREE_CODE (arg) == SSA_NAME + && param_type + && get_ptr_nonnull (arg)) + { + jfunc->vr_known = true; + jfunc->m_vr.type = VR_ANTI_RANGE; + jfunc->m_vr.min = build_int_cst (TREE_TYPE (arg), 0); + jfunc->m_vr.max = build_int_cst (TREE_TYPE (arg), 0); + jfunc->m_vr.equiv = NULL; + } + else + gcc_assert (!jfunc->vr_known); + } + else { wide_int min, max; value_range_type type; @@ -5602,27 +5617,37 @@ ipcp_update_vr (struct cgraph_node *node) continue; if (vr[i].known - && INTEGRAL_TYPE_P (TREE_TYPE (ddef)) - && !POINTER_TYPE_P (TREE_TYPE (ddef)) && (vr[i].type == VR_RANGE || vr[i].type == VR_ANTI_RANGE)) { tree type = TREE_TYPE (ddef); unsigned prec = TYPE_PRECISION (type); - if (dump_file) + if (INTEGRAL_TYPE_P (TREE_TYPE (ddef))) + { + if (dump_file) + { + fprintf (dump_file, "Setting value range of param %u ", i); + fprintf (dump_file, "%s[", + (vr[i].type == VR_ANTI_RANGE) ? "~" : ""); + print_decs (vr[i].min, dump_file); + fprintf (dump_file, ", "); + print_decs (vr[i].max, dump_file); + fprintf (dump_file, "]\n"); + } + set_range_info (ddef, vr[i].type, + wide_int_storage::from (vr[i].min, prec, + TYPE_SIGN (type)), + wide_int_storage::from (vr[i].max, prec, + TYPE_SIGN (type))); + } + else if (POINTER_TYPE_P (TREE_TYPE (ddef)) + && vr[i].type == VR_ANTI_RANGE + && wi::eq_p (vr[i].min, 0) + && wi::eq_p (vr[i].max, 0)) { - fprintf (dump_file, "Setting value range of param %u ", i); - fprintf (dump_file, "%s[", - (vr[i].type == VR_ANTI_RANGE) ? "~" : ""); - print_decs (vr[i].min, dump_file); - fprintf (dump_file, ", "); - print_decs (vr[i].max, dump_file); - fprintf (dump_file, "]\n"); + if (dump_file) + fprintf (dump_file, "Setting nonnull for %u\n", i); + set_ptr_nonnull (ddef); } - set_range_info (ddef, vr[i].type, - wide_int_storage::from (vr[i].min, prec, - TYPE_SIGN (type)), - wide_int_storage::from (vr[i].max, prec, - TYPE_SIGN (type))); } } } diff --git a/gcc/testsuite/gcc.dg/ipa/vrp4.c b/gcc/testsuite/gcc.dg/ipa/vrp4.c new file mode 100644 index 0000000..d7e1f26 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/vrp4.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-cp-details" } */ + +static __attribute__((noinline, noclone)) +int foo (int *p) +{ + if (!p) + return 0; + *p = 1; +} + +struct st +{ + int a; + int b; +}; + +int bar (struct st *s) +{ + + if (!s) + return 0; + foo (&s->a); + foo (&s->b); +} + +/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */ -- 2.7.4