Walt Brainerd <[log in to unmask]> wrote:
...
>Does anybody think a compiler should not be allowed to do
>the kinds of optimizations we have been talking about:
>moving invariant code out of loops, removing "dead" code,
>inlining procedures, combining expressions in more than
>one statement (Interp #1?) etc?
Well, yes and no. If doing any of these things changes the standard's
specified semantics of the program, then they shouldn't be allowed.
If they change the meaning, but with respect to something not
covered by the standard, it's a gray area.
For example, the code given earlier:
T = B+C
D = A * T
If the compiler replaces this with:
D = A * (B+C)
because it notices that T is used nowhere else in the program, I think
this is a valid optimization. It may even be valid if the second version
carries different precision than the first, if the variation of precision
is not covered by the standard. That is, if all the variables are declared
the same type and the processor just happens to carry extra precision
within expressions than that type specifies, I think the optimization
might be valid. I don't know.
However, if all the variables except T are declared double precision
and T is declared default real, I believe the optimization should not be
allowed. Instead, you should be required to do something like:
D = C * REAL(A+B, kind(0.0))
Because it may be part of the user's intent to chop the intermediate
value to single. But, as I said before, I don't know. I just have an
opinion here. This is the kind of thing that deserves some attention
(when the committee gets some spare time).
--
J. Giles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|