From patchwork Wed Oct 19 02:12:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 78159 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp15941qge; Tue, 18 Oct 2016 19:12:47 -0700 (PDT) X-Received: by 10.99.63.3 with SMTP id m3mr5132130pga.62.1476843167784; Tue, 18 Oct 2016 19:12:47 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o25si34564500pge.141.2016.10.18.19.12.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 19:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-438970-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-438970-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-438970-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 :to:subject:message-id:date:mime-version:content-type; q=dns; s= default; b=WvluuBbEleV2dModrYCAbJugMyijK0AmRTOaEiusie1u5zUrNSS7C LIr0VKv7LvlVc24aLluuCt4lCoktGhLgHhy71dv1Y7ZjtU8ead+vYH0IwKkrrIVl splZ2AI9fzaMH5KRMo+O77guIz52f6HN/1HsagE9Q/J7dlhsmYNT9c= 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:subject:message-id:date:mime-version:content-type; s= default; bh=gPC4jtzxOKr3rH9y4TrBZpAXKHc=; b=qSRN30oo/oU3bdsYAt6Z sNA/VV0QYu5ezcmtDrvCjJsdqeZDWj8u3cxWYiAhZzd+UKy3LKVetkxfbTqwlIi1 IGN2h6+DJJZLIaJ7vP9KQGOUcnBtbD/XnVBh4oBz5ZHIVITzgk4tuVKdhD7b5OhB LwL2O+rBnw4Hb1d9MWARyqg= Received: (qmail 68878 invoked by alias); 19 Oct 2016 02:12:26 -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 68661 invoked by uid 89); 19 Oct 2016 02:12:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=fdumptreevrp1, fdump-tree-vrp1 X-HELO: mail-pf0-f179.google.com Received: from mail-pf0-f179.google.com (HELO mail-pf0-f179.google.com) (209.85.192.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 02:12:14 +0000 Received: by mail-pf0-f179.google.com with SMTP id s8so6498754pfj.2 for ; Tue, 18 Oct 2016 19:12:14 -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:to:subject:message-id:date:user-agent :mime-version; bh=0wEIE3g2qDCXSMJHT+UBTtBCIOM2RccBU8ckpUDlQ+4=; b=nGXPzQvNadZp2CYHby94yNyv5FcLfHNImzdO6l8TTjFMruN93gOkwbEStCjZ5RBzTw 53zwcVPI3I6zJlBD2HxjQIuqwJrU+CqStVpoBcCV53AtNPG1C1iWO2AjbM0jT4uGlauw 703YIuqG4HLH0/IUwtA4hRYTVCVTHtjjxL8hDG9Z8Zq6d6Mr1KgpQbHxR1GSiXEOjGnT U5xRaBjgM64Cogm2LOvI3GWKXd3LUNf32HUdneULWpCNIa8EUcUlO9dH3SIelWlkFHp3 hasYmKZ5/0N6O4aWDUmX2H2uqN8DF++VQysQc2zhqxUwqCtymOjAWxvMP7XEzOSFTOBh M2TA== X-Gm-Message-State: AA6/9RnyZBLB3MMCQ07nD4W24BA/Un9hsTf3pXDz+YhdpLHDhkUVVXRuKAjuxO1eU+twcmEI X-Received: by 10.99.123.90 with SMTP id k26mr5089973pgn.23.1476843132883; Tue, 18 Oct 2016 19:12:12 -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 x190sm58798373pfd.20.2016.10.18.19.12.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 19:12:12 -0700 (PDT) From: kugan To: Richard Biener , Jan Hubicka , "gcc-patches@gcc.gnu.org" Subject: [RFC][IPA-VRP] ADDR_EXPR and nonnull Message-ID: Date: Wed, 19 Oct 2016 13:12:08 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, While computing jump function value range for pointer, I am wondering if we can assume that any tree with ADDR_EXPR will be nonnull. That is, in cases like: int arr[10]; foo (&arr[1]); OR struct st { int a; int b; }; struct st s2; foo (&s2.a); Attached patch tries to do this. I am not sure if this can be wrong. Any thoughts? Attached patch bootstraps and regression testing didn't introduce any new regressions. Thanks, Kugan gcc/ChangeLog: 2016-10-19 Kugan Vivekanandarajah * ipa-prop.c (ipa_compute_jump_functions_for_edge): Set value range to nonull for ADDR_EXPR. gcc/testsuite/ChangeLog: 2016-10-19 Kugan Vivekanandarajah * gcc.dg/ipa/vrp5.c: New test. * gcc.dg/ipa/vrp6.c: New test. diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 353b638..b795d30 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1670,9 +1670,10 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, if (POINTER_TYPE_P (TREE_TYPE (arg))) { - if (TREE_CODE (arg) == SSA_NAME - && param_type - && get_ptr_nonnull (arg)) + if ((TREE_CODE (arg) == SSA_NAME + && param_type + && get_ptr_nonnull (arg)) + || (TREE_CODE (arg) == ADDR_EXPR)) { jfunc->vr_known = true; jfunc->m_vr.type = VR_ANTI_RANGE; diff --git a/gcc/testsuite/gcc.dg/ipa/vrp5.c b/gcc/testsuite/gcc.dg/ipa/vrp5.c index e69de29..8e43a65 100644 --- a/gcc/testsuite/gcc.dg/ipa/vrp5.c +++ b/gcc/testsuite/gcc.dg/ipa/vrp5.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-cp-details -fdump-tree-vrp1" } */ + +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) +{ +int arr[10]; + if (!s) + return 0; + foo (&s->a); + foo (&arr[1]); +} + +/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */ +/* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */ diff --git a/gcc/testsuite/gcc.dg/ipa/vrp6.c b/gcc/testsuite/gcc.dg/ipa/vrp6.c index e69de29..f837758 100644 --- a/gcc/testsuite/gcc.dg/ipa/vrp6.c +++ b/gcc/testsuite/gcc.dg/ipa/vrp6.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-cp-details -fdump-tree-vrp1" } */ + +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) +{ +struct st s2; + if (!s) + return 0; + foo (&s->a); + foo (&s2.a); +} + +/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */ +/* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */