From patchwork Wed Jan 11 08:54:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 713628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tz2lb0PvLz9snk for ; Wed, 11 Jan 2017 19:55:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HMa1HPQA"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=tEUxGRJ0KsA/Vb8UA h35EPaFEAGPetj7ls6R+LB7w0Fmks9GYVUqLpw7CvJgPNX8ARsMMYJ0M9tOyHVzA 85G56NXfTeP7r+P5zaFkQF7vXqKYJdeF1iQL67P8POGPms6pqk4RZHDtrrZifqi0 DrSWghTMury4tPM9mwADYaDYM8= 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:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=xJMexwLM2jCM6A05enlcpPe 8sQ4=; b=HMa1HPQAUoqYphZvtQIaQXEDwHDEbGck0vd6Dfb9mTESv+4ryYypb7/ iTKr8Sg7CutLr4PXmoFrMN+YwmuGarQuNkzxCOxsOKh+YpfIdn97O/4Us/2O60Tq yQnKEvu8/dz/+MQJoCtJM/H4TPRLekRZFXXEBCcAT2UIufFERZmo= Received: (qmail 16822 invoked by alias); 11 Jan 2017 08:54:58 -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 16808 invoked by uid 89); 11 Jan 2017 08:54:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=boo, *symbol, 2017-01-11 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jan 2017 08:54:56 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21320369C3; Wed, 11 Jan 2017 08:54:56 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-54.ams2.redhat.com [10.36.116.54]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0B8sqKY000993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 11 Jan 2017 03:54:54 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v0B8snjb010338; Wed, 11 Jan 2017 09:54:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v0B8slJK010337; Wed, 11 Jan 2017 09:54:47 +0100 Date: Wed, 11 Jan 2017 09:54:47 +0100 From: Jakub Jelinek To: Richard Biener Cc: Jason Merrill , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Optimize n + 1 for automatic n array (PR c++/71537) Message-ID: <20170111085447.GH21933@tucnak> Reply-To: Jakub Jelinek References: <20170110224033.GC21933@tucnak> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes On Wed, Jan 11, 2017 at 09:31:38AM +0100, Richard Biener wrote: > > Or shall I add the function local address check into maybe_nonzero_address > > instead (return 1 for those)? > > Yes please, and cleanup the other user of maybe_nonzero_address then > (which contains the code you added). Ok, I'll bootstrap/regtest following patch then: 2017-01-11 Jakub Jelinek PR c++/71537 * fold-const.c (maybe_nonzero_address): Return 1 for function local objects. (tree_single_nonzero_warnv_p): Don't handle function local objects here. * g++.dg/cpp1y/constexpr-71537.C: New test. Jakub --- gcc/fold-const.c.jj 2017-01-11 09:36:36.673864630 +0100 +++ gcc/fold-const.c 2017-01-11 09:44:20.004660940 +0100 @@ -8171,7 +8171,8 @@ pointer_may_wrap_p (tree base, tree offs /* Return a positive integer when the symbol DECL is known to have a nonzero address, zero when it's known not to (e.g., it's a weak symbol), and a negative integer when the symbol is not yet in the - symbol table and so whether or not its address is zero is unknown. */ + symbol table and so whether or not its address is zero is unknown. + For function local objects always return positive integer. */ static int maybe_nonzero_address (tree decl) { @@ -8179,6 +8180,13 @@ maybe_nonzero_address (tree decl) if (struct symtab_node *symbol = symtab_node::get_create (decl)) return symbol->nonzero_address (); + /* Function local objects are never NULL. */ + if (DECL_P (decl) + && (DECL_CONTEXT (decl) + && TREE_CODE (DECL_CONTEXT (decl)) == FUNCTION_DECL + && auto_var_in_fn_p (decl, DECL_CONTEXT (decl)))) + return 1; + return -1; } @@ -13276,13 +13284,6 @@ tree_single_nonzero_warnv_p (tree t, boo if (nonzero_addr >= 0) return nonzero_addr; - /* Function local objects are never NULL. */ - if (DECL_P (base) - && (DECL_CONTEXT (base) - && TREE_CODE (DECL_CONTEXT (base)) == FUNCTION_DECL - && auto_var_in_fn_p (base, DECL_CONTEXT (base)))) - return true; - /* Constants are never weak. */ if (CONSTANT_CLASS_P (base)) return true; --- gcc/testsuite/g++.dg/cpp1y/constexpr-71537.C.jj 2017-01-11 09:41:32.103909019 +0100 +++ gcc/testsuite/g++.dg/cpp1y/constexpr-71537.C 2017-01-11 09:41:32.103909019 +0100 @@ -0,0 +1,14 @@ +// PR c++/71537 +// { dg-do compile { target c++14 } } + +constexpr bool +foo () +{ + constexpr int n[42] = { 1 }; + constexpr int o = n ? 1 : 0; + constexpr int p = n + 1 ? 1 : 0; + constexpr int q = "abc" + 1 ? 1 : 0; + return p + p + q == 3; +} + +static_assert (foo (), "");