From patchwork Fri Oct 21 07:38:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 78604 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1164126qge; Fri, 21 Oct 2016 00:39:03 -0700 (PDT) X-Received: by 10.99.188.1 with SMTP id q1mr7431782pge.145.1477035543154; Fri, 21 Oct 2016 00:39:03 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 88si1460522pfs.216.2016.10.21.00.39.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 00:39:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439190-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-439190-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439190-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=WeS0GxjlcFy0VoMAg bvNWGebwB7epMim7yw8KCjDqUukCSdm49ZR9awFT2eXmif4YJAK4Q5ANSsLiazRo U90+sXqe+foIxSt59uR7PrdMMRXBIakBAYKWAGKAu3okb13Uat9RR75dhq1rYzAa bD3IRWZZr3rungmKK9jix+m0L4= 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=YD6sHDBWp3tSxQOlRr5Vcbd Ykhg=; b=YzW8BH7d96Y9kCOzEYQkDEZT8uSPv5YH8RLjxR4f9SSd8wNef1rmYGo jV4g377xKEPzeIr6gQ6bIpbkuV8IrpJidBbbNITYe73u+qd6lgzasEb8iC76mqzx mkHTEa5EghZ04WPoAVKJVvT2sX04GLz8IGkQ9Tma3j2qJXrkDOB8= Received: (qmail 6766 invoked by alias); 21 Oct 2016 07:38:49 -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 6746 invoked by uid 89); 21 Oct 2016 07:38:47 -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=HX-Received:Fri X-HELO: mail-pf0-f176.google.com Received: from mail-pf0-f176.google.com (HELO mail-pf0-f176.google.com) (209.85.192.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Oct 2016 07:38:37 +0000 Received: by mail-pf0-f176.google.com with SMTP id r16so52384456pfg.1 for ; Fri, 21 Oct 2016 00:38:37 -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=tEAFMxRUSmr2GXnw/NnFaAs5FtuIKAID1uhfmaDIzuI=; b=M79SBE6JwiVClprOVScHaDayod9wNHtyyjDjtQoOHov/QYm3CAzCCLWk4FsDiZDYZQ 9fPPXsny70Ut82ohw50m2ELEXTc3516cLIYjViNAv1XPb4i7813ZF+FAP4PBnbsa1cTx PP+CWupN7OPCVWVWV7TaHtPtxxSEy/EVosBlmYR/EIxyTViBycD3p7aHHRNkna0M3KEI D5k12ptymMYfVyCu+/xjrCpz8akRSZATIB77USauzLRYWSDanzsImcGsS9LIAZwut5Kr o7q+J+jGQOyp6U/EyI8G/4t3Ojn5gZ3BfVaCEufi4nuQBuJVyRGue0/lfLI9SAxS5T7j 9urw== X-Gm-Message-State: AA6/9Rl8E2lMwGIw1tECSGZGQfFhHe+NA1YucMdMRt4TvlJxJJFa6mBoi9hnUJIOG3BSxKXe X-Received: by 10.98.192.135 with SMTP id g7mr9160641pfk.58.1477035516175; Fri, 21 Oct 2016 00:38:36 -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 j17sm2444208pfe.79.2016.10.21.00.38.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 00:38:35 -0700 (PDT) Subject: Re: [RFC][IPA-VRP] ADDR_EXPR and nonnull To: Richard Biener References: <0987d0d3-9b7b-eeb8-cf2a-17d1d0df7f49@linaro.org> <20161019142620.GA69032@kam.mff.cuni.cz> <26222603-662f-57b9-8087-724cc5e88191@linaro.org> <76ab5854-4c4e-ae4a-8d33-e2b1bdd02522@linaro.org> <20161020121524.GC19926@kam.mff.cuni.cz> Cc: Jan Hubicka , "gcc-patches@gcc.gnu.org" From: kugan Message-ID: <0ef084d3-b9fa-4623-d353-c14a16c0b907@linaro.org> Date: Fri, 21 Oct 2016 18:38:31 +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: X-IsSubscribed: yes On 21/10/16 18:16, Richard Biener wrote: > On Fri, 21 Oct 2016, kugan wrote: > >> Hi, >> >> On 20/10/16 23:15, Jan Hubicka wrote: >>>> Hi Richard, >>>> >>>> >>>> On 20/10/16 18:41, Richard Biener wrote: >>>>> On Thu, 20 Oct 2016, kugan wrote: >>>>> >>>>>> >>>>>> >>>>>> 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. */ >>>>> >>>>> "constant" doesn't matter. You want >>>>> >>>>> if (TREE_CODE (base) == CONST_DECL >>>>> || TREE_CODE (base) == PARM_DECL >>>>> || TREE_CODE (base) == RESULT_DECL) >>>>> addr_nonzero = true; >>>>> else if (VAR_P (base)) >>> Better to check decl_in_symtab_p (decl) >>>>> addr_nonzero = ! is_global_var (base) || (varpool_node::get >>>>> (base)->nonzero_address ()); >>> and symtab_node::get. >>> >>> I wonder if we can't unify the logic with tree_expr_nonzero_warnv_p >>> and corresponding vrp code? >> Are you saying that we should export tree_expr_nonzero_warnv_p and use here >> with the logic from above added to tree_expr_nonzero_warnv_p as shown in the >> attached patch? > > tree_single_nonzero_warnv_p already handles this correctly via > maybe_nonzero_address. And tree_single_nonzero_warnv_p is already > exported. Indeed. maybe_nonzero_address does look at node->nonzero_address () but we still seems to miss TREE_CODE (base) == PARM_DECL and TREE_CODE (base) == RESULT_DECL. Does the attached patch looks OK if no regressions? Thanks, Kugan > > Richard. > >> Thanks, >> Kugan >> >>> >>> Otherwise the patch looks fine to me. >>> Honza >>> >> > diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 89ed89d..3c1803f 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -13402,7 +13402,9 @@ tree_single_nonzero_warnv_p (tree t, bool *strict_overflow_p) return true; /* Constants are never weak. */ - if (CONSTANT_CLASS_P (base)) + if (CONSTANT_CLASS_P (base) + || TREE_CODE (base) == PARM_DECL + || TREE_CODE (base) == RESULT_DECL) return true; return false; diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 353b638..939fd1d 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -1670,9 +1670,20 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, if (POINTER_TYPE_P (TREE_TYPE (arg))) { + bool addr_nonzero = false; + bool strict_overflow = false; + if (TREE_CODE (arg) == SSA_NAME && param_type && get_ptr_nonnull (arg)) + addr_nonzero = true; + else if (tree_single_nonzero_warnv_p (arg, &strict_overflow)) + { + if (!strict_overflow) + addr_nonzero = true; + } + + if (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" } } */