From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31589 invoked by alias); 29 Apr 2002 12:39:51 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 31562 invoked from network); 29 Apr 2002 12:39:45 -0000 Received: from unknown (HELO web13608.mail.yahoo.com) (216.136.175.119) by sources.redhat.com with SMTP; 29 Apr 2002 12:39:45 -0000 Message-ID: <20020429123944.37948.qmail@web13608.mail.yahoo.com> Received: from [32.97.110.76] by web13608.mail.yahoo.com via HTTP; Mon, 29 Apr 2002 05:39:44 PDT Date: Mon, 29 Apr 2002 05:44:00 -0000 From: Mark Dettinger Subject: Re: pure and const functions To: gcc@gcc.gnu.org Cc: dewar@gnat.com In-Reply-To: <20020429105955.D08B4F28F4@nile.gnat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-04/txt/msg01533.txt.bz2 > a) having no effects except the return value > b) return value depends only on the parameters > c) return value depends on global variables > > Condition a) is too strong for removal of duplicate calls, since it > eliminates considering memo functions as pure. Yes, but I think that's okay. There are cases where duplicate calls to a non-pure memoizing function could be removed too, but how should the compiler determine which side-effects can be ignored? All we say is that if condition a) is fulfilled, we are on the safe side. > Conditions b) and c) are quite different from an optimization point of view. > In GNAT we define a pure function as one for which it is permissible to > optimize away multiple calls with provably identical parameter calls. If I understood it correctly, that would be a "const" function in gcc. Sometimes pure is enough to optimize, sometimes you need const. foo()+foo() ---> 2*foo() is possible, if foo() is pure a=foo(); a=foo(); n++; ---> n++; is only possible, if foo() is const, b=foo(); b=a; since foo() might depend on the global var n -Mark Dettinger __________________________________________________ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com