This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] Removing useless/redundant "const" calls
- From: Michael Matz <matz at suse dot de>
- To: law at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 12 Jun 2003 09:27:08 +0200 (CEST)
- Subject: Re: [tree-ssa] Removing useless/redundant "const" calls
Hi,
On Thu, 12 Jun 2003 law@redhat.com wrote:
> Given two invocations of a pure function with the same inputs, will the
> pure function always return the same value?
No, it can return different values each time. For instance:
static int count;
void inc(void) { count++; }
int get(void) {return count;}
Here get() is a pure function whose return value depends on how often
inc() was called before.
> If the answer is no, then we'll need to distinguish between pure and
> const functions later -- simply clearing TREE_SIDE_EFFECTS would result
> in incorrect code.
I see. But I guess this can be done?
> Is a pure function allowed to read volatile memory?
No. Reading volatile mem is defined to have unpredictable side-effects.
A pure function is defined to have no side effects. Therefore it can't
read volatile mem (and similar to "const" it also can't call other
non-pure functions).
Ciao,
Michael.