Re: Function PRESENT and logical combinations

From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 06/16/04


Date: Wed, 16 Jun 2004 04:06:40 GMT

Ron Shepard wrote:
...
> What if the statement is simply
>
> A = F(x)
>
> but the local variable A is not referenced afterwards? Is the
> compiler allowed to optimize away entirely the function reference?

It can if it can prove that F has no side-effects on X,
some COMMON or MODULE variable, or some SAVEd
internal value, and that it does no I/O. The rule is that the
program must behave as if the execution sequence was
followed. That's well defined by the standard. Similarly
for your other examples. No compiler I know of violates
this.

If F is declared PURE, then the processor is free to assume
all those properties.

-- 
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."  -- C. A. R. Hoare