home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!decwrl!deccrl!news.crl.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!quark.enet.dec.com!lionel
- From: lionel@quark.enet.dec.com (Steve Lionel)
- Newsgroups: comp.lang.fortran
- Subject: Re: Legal optimization?
- Message-ID: <1992Nov23.174940.19270@e2big.mko.dec.com>
- Date: 23 Nov 92 17:49:40 GMT
- References: <1992Nov21.114131.24902@alf.uib.no> <BURLEY.92Nov23105853@apple-gunkies.gnu.ai.mit.edu>
- Sender: usenet@e2big.mko.dec.com (Mr. USENET)
- Reply-To: lionel@quark.enet.dec.com (Steve Lionel)
- Organization: Digital Equipment Corporation, Nashua NH
- Lines: 53
-
-
- |> >>>>> "Per" == Per Steinar Iversen <iversen@vsfys1.fi.uib.no> writes:
- |>
- |> Per> One of the students here uses VAX FORTRAN to calculate various things for his
- |> Per> thesis. Recently he had some problems, which were traced down to a real bug.
- |> Per> However: A result of the bug was that a square root of a negative REAL occurred.
- |> Per> Yet this never made the program crash! When either a WRITE statement was
- |> Per> inserted on the next line after the SQRT or the optimization was turned off,
- |> Per> then the program crashed properly... Presumably the optimizer transforms the
- |> Per> code into something which is OK if the values are *not* negative. At least in
- |> Per> this program however the results were just garbage if the negative root occurred.
- |>
- |> Welcome to the world of code optimization! I don't think that the standard
- |> has any meaning once the optimizer has gotten hold of it. Rule: the optimizer
- |> is only as good as the person that wrote it. Some of them are damn good. Most
- |> are good at local 10-20 line optimization. It is when higher level
- |> optimization (i.e., so-called global optimization and inlining) is attempted
- |> that things can go wrong.
- |>
-
- I didn't see the original of this, but I think I can figure out what happened,
- and it's simpler and less sinister than some seem to think.
-
- The VAX FORTRAN compiler can remove code whose results are unused. If a
- SQRT of a negative value was computed but the result never used, the SQRT itself
- would also be removed. Adding the WRITE of the value caused the result to
- be used and hence the error occurred. This is a classic optimization
- technique and perfectly valid.
-
- It is true the Fortran standard doesn't say much about exceptions. I like what
- the Ada standard has to say in this regard. Summarizing, section 11.6 says:
-
- 1. If the "canonical" order of operations does not produce an
- exception, the reordered operations must not produce an exception.
-
- 2. A "predefined operation" (ie. an intrinsic or operator) doesn't
- have to be performed if its only effect is to cause an
- exception.
-
- I take exception to the comment that "the standard [has no] meaning once the
- optimizer has gotten hold of it", and I believe my sentiment would be shared
- by any reputable compiler developer. You might be able to ask for optimizations
- which make assumptions contrary to or unspecified in the standard, but a
- standard-conforming program should execute in a standard-conforming manner no
- matter what optimizations are applied to it. The most clever optimizations in
- the world are worthless if you end up with wrong results.
- --
-
- Steve Lionel lionel@quark.enet.dec.com
- SDT Languages Group
- Digital Equipment Corporation
- 110 Spit Brook Road
- Nashua, NH 03062
-