From patchwork Thu Oct 20 03:13:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 78390 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp570032qge; Wed, 19 Oct 2016 20:14:05 -0700 (PDT) X-Received: by 10.98.67.133 with SMTP id l5mr17034810pfi.170.1476933245900; Wed, 19 Oct 2016 20:14:05 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id x2si43120763pfj.257.2016.10.19.20.14.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 20:14:05 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439074-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-439074-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439074-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:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=A7zW9FRcRNnCZSeNy jFjZ4SsYd2vnNkP/4EdidqgMuUZeC0Acz8gZJFOISC8WxO7+Q7/TKrIjTYhv0qFp WL57jtXJPvTESS9fXUjh2FqzK5sUg8CvxUT/Tmel6R60wHQfQpua0xz69z8yvdN5 13QQ3qOp9HX+RGfmAeE9UdbW3M= 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:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=z8+M+LoAK2COWzc9uhptSEc zEtQ=; b=ISF1SJlr8AS5Ln4niBT5RHwBpcr3MKjMd+pzSGdeaPkuz4wfiUiEwLw JPPaOfjZ6/73ueUKH+Zvil0exOyaPqvWP5UQ1DvLdArZoCgSTLp0LioQni6icZyY ZkD3KGnPRPSwOXszGXh85KkT3gQLeANUidinO3LqZFYFHD22Pti4= Received: (qmail 84612 invoked by alias); 20 Oct 2016 03:13:50 -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 84595 invoked by uid 89); 20 Oct 2016 03:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=honza, Honza, nonzero_address X-HELO: mail-pf0-f170.google.com Received: from mail-pf0-f170.google.com (HELO mail-pf0-f170.google.com) (209.85.192.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Oct 2016 03:13:38 +0000 Received: by mail-pf0-f170.google.com with SMTP id s8so27036626pfj.2 for ; Wed, 19 Oct 2016 20:13:38 -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:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=E/+/JsJ9a+wbur4/pGFwaXus/p5sLkzR98lGkL1U/ds=; b=U3/SRBxTxc4zu48/HxLgK7piFDh0RXV9ppO5SxQcg/TZCLl3En67Q+JvvZrRO/pFRP c8e9B3sRIhubtu61y4fzoPU00+BSv/nLTrp/sNaqZw8YZLwqrRVUSgY3nd7JKZ250U4m cEowfaPB/IxFUe9H1VZGroMvhJAc3BPTHamMZVr9aK/RmnS0VsMCIA2Zbf1B3fz7s4T+ w1afWPKhhAutP0HRxpQfw5H+Jn387z2+UT5FMeVElo7opvSqphLmlkGZ/RZ2Hdr+yYWI E+sCkNZ1iDvxqqcI4R3/iQv2hiwmva6PZTdkLbkqimTsjrFVADhHdMsv2DTpsV4FCghu GeDA== X-Gm-Message-State: AA6/9RkbC2HPC/z7mVMjKzVhvEoaxEbrhXZ4jYzX27C5lAbcP12BB0oiQwLlxRHLK84pPn4s X-Received: by 10.98.92.65 with SMTP id q62mr17293276pfb.24.1476933217302; Wed, 19 Oct 2016 20:13:37 -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 zh13sm67121402pab.4.2016.10.19.20.13.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 20:13:36 -0700 (PDT) Subject: Re: [RFC][IPA-VRP] ADDR_EXPR and nonnull To: Jan Hubicka , Richard Biener References: <0987d0d3-9b7b-eeb8-cf2a-17d1d0df7f49@linaro.org> <20161019142620.GA69032@kam.mff.cuni.cz> Cc: "gcc-patches@gcc.gnu.org" From: kugan Message-ID: <26222603-662f-57b9-8087-724cc5e88191@linaro.org> Date: Thu, 20 Oct 2016 14:13:32 +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: <20161019142620.GA69032@kam.mff.cuni.cz> X-IsSubscribed: yes On 20/10/16 01:26, Jan Hubicka wrote: >>> Would excluding weak symbols (I believe I can check DECL_WEAK for this) good >>> enough. Or looking for acceptable subset would work? >> >> I think we should add a symtab helper to tell if address_nonzero_p (if >> that doesn't aleady exist). > > We have node->nonzero_address() Thanks for the pointer. Here is an attempt. Does this look OK? + if (TREE_CODE (arg) == ADDR_EXPR) + { + /* See if the AADR_EXPR is nonnull. */ + varpool_node *node = NULL; + tree base = TREE_OPERAND (arg, 0); + base = get_base_address (base); + + if (decl_address_ip_invariant_p (base) + || !is_global_var (base)) + { + /* If the symbol address is local or + constant. */ + addr_nonzero = true; + } + else + { + /* If symbol address is nonzero_address. */ + node = varpool_node::get (base); + if (node && node->nonzero_address ()) + addr_nonzero = true; + } + } Attached patch passes bootstrap and regression testing on x86_64-linu-gnu. Thanks, Kugan > > Honza >> >> Richard. >> >>> Thanks, >>> Kugan >>> >>>> >>>> Richard. >>>> >>>>> 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. >>>>> >>>> >>> >>> >> >> -- >> Richard Biener >> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg) diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 353b638..affd8b9 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1670,9 +1670,35 @@ 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)) + bool addr_nonzero = false; + + if (TREE_CODE (arg) == ADDR_EXPR) + { + /* See if the AADR_EXPR is nonnull. */ + varpool_node *node = NULL; + tree base = TREE_OPERAND (arg, 0); + base = get_base_address (base); + + if (decl_address_ip_invariant_p (base) + || !is_global_var (base)) + { + /* If the symbol address is local or + constant. */ + addr_nonzero = true; + } + else + { + /* If symbol address is nonzero_address. */ + node = varpool_node::get (base); + if (node && node->nonzero_address ()) + addr_nonzero = true; + } + } + + if ((TREE_CODE (arg) == SSA_NAME + && param_type + && get_ptr_nonnull (arg)) + || addr_nonzero) { 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..571798d 100644 --- a/gcc/testsuite/gcc.dg/ipa/vrp5.c +++ b/gcc/testsuite/gcc.dg/ipa/vrp5.c @@ -0,0 +1,34 @@ +/* { 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 arr1[10]; +int a; +int bar (struct st *s) +{ + int arr2[10]; + int b; + if (!s) + return 0; + foo (&s->a); + foo (&a); + foo (&b); + foo (&arr1[1]); + foo (&arr2[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..971db44 100644 --- a/gcc/testsuite/gcc.dg/ipa/vrp6.c +++ b/gcc/testsuite/gcc.dg/ipa/vrp6.c @@ -0,0 +1,34 @@ +/* { 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; +}; + +struct st s2; +int a; +int bar (struct st *s) +{ + struct st s3; + int b; + if (!s) + return 0; + foo (&s->a); + foo (&s2.a); + foo (&s3.a); + foo (&a); + foo (&b); +} + +/* { dg-final { scan-ipa-dump "Setting nonnull for 0" "cp" } } */ +/* { dg-final { scan-tree-dump-times "if" 1 "vrp1" } } */