Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!uunet!bywater!arnor!prener!prener From: prener@watson.ibm.com (Dan Prener) Newsgroups: comp.arch Subject: Re: IEEE arithmetic (Goldberg paper) Message-ID: <1991Jun22.003029.16748@watson.ibm.com> Date: 22 Jun 91 00:30:29 GMT References: <9106190124.AA27410@ucbvax.Berkeley.EDU> Sender: news@watson.ibm.com (NNTP News Poster) Reply-To: prener@prener.watson.ibm.com (Dan Prener) Organization: IBM T.J. Watson Research Center Lines: 74 Nntp-Posting-Host: prener In article <9106190124.AA27410@ucbvax.Berkeley.EDU>, jbs@WATSON.IBM.COM writes: |> |> I said: |> >I think that if a (legal) program behaves differently when compiled with |> >and without optimization that then the compiler is broken. Perhaps you |> >disagree. |> Malcolm said: |> B = 5.0 |> IF ( ( B .GT. 3.0 ) .OR. MYTEST(A) ) |> PRINT some diagnotic messages |> LOGICAL FUNCTION MYTEST(X) |> REAL X |> MYTEST = some boolean work |> PRINT a few diagnostics on the screen |> RETURN |> END |> I modified this to: |> LOGICAL*4 MYTEST |> B = 5.0 |> IF ( ( B .GT. 3.0 ) .OR. MYTEST(B) )THEN |> WRITE(6,*)' MAIN' |> ENDIF |> END |> LOGICAL FUNCTION MYTEST(X) |> REAL X |> WRITE(6,*)' MYTEST' |> MYTEST = .TRUE. |> RETURN |> END |> I checked the behavior with the IBM VS Fortran and Xlf compi- |> lers. In both cases the behavior was not changed by optimization. The |> behavior differs between the two compilers but that is a different is- |> sue. So this example will not convince me that I'm wrong. (Actually |> I later softened my original statement to say it is undesirable for |> optimization to affect a program's behavior.) |> James B. Shearer As immodest as it might be for me to agree with my colleague, I must agree with James Shearer. Indeed, the spirit of FORTRAN is, overwhelmingly, that a program whose behavior is changed by optimization is not a legal program. In particular, I quote from the FORTRAN '77 standard It is not necessary for a processor to evaluate all of the operands of an expression if the value of the expression can be determined otherwise. This principle is most often applicable to logical expressions, but it applies to all expressions. For example, in evaluating the logical expression X .GT. Y .OR. L(Z) where X, Y, and Z are real, and L is a logical function, the function reference L(Z) need not be evaluated if X is greater than Y. to show that the compiler may do it either way. And I cite another passage from the same standard For example the statements A(I) = F(I) Y = G(X) + X are prohibited if the reference to F defines I or the reference to G defines X. which suggests that programs that admit more than one correct interpretation are illegal. I would say that, since the program(s) offered above are, according to the language standard, non-deterministic, then they are illegal. Note that optimization has nothing to do with this. According to the standard, a compiler could correctly produce a program which would call the function MYTEST or not depending upon the time of day at which it was run. -- Dan Prener (prener @ watson.ibm.com)