home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!ames!agate!agate.berkeley.edu!dodd
- From: dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd)
- Newsgroups: comp.lang.fortran
- Subject: Re: Legal optimization?
- Date: 22 Nov 92 06:56:07
- Organization: Dept of Chemical Engineering, Polytechnic Univ, NY, USA
- Lines: 45
- Message-ID: <DODD.92Nov22065607@mycenae.cchem.berkeley.edu>
- References: <1992Nov21.114131.24902@alf.uib.no>
- Reply-To: dodd@roebling.poly.edu
- NNTP-Posting-Host: mycenae.cchem.berkeley.edu
- In-reply-to: iversen@dsfys1.fi.uib.no's message of Sat, 21 Nov 92 11:41:31 GMT
-
-
- >>>>> "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.
-
- Per> The compiler is VAX FORTRAN V5.8-155 under VMS 5.5. So far I always felt safe
- Per> if my programs compiled and ran with
- Per> FORTRAN/CHECK=ALL/STANDARD=ALL/WARNING=(GENERAL,DECLARATIONS), but I guess I
- Per> should add /NOOPTIMIZE too.
-
- Per> My question is more philosophical perhaps: Are such transformations of the
- Per> code actually legal, is the compiler performing within the standard?
-
- 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.
-
- Two things that I do to stop the optimizer from screwing me:
-
- (1) compile and run with and without the optimizer -- obviously, the results
- should be identical -- with unix f77 this can be done with -g typically
- without any -O[1234].
-
- (2) Keep sub-programs small. This lessens the chance of the optimizer from
- assuming too much.
-
- I used VMS for five years and discovered no real `bugs' in the optimizer but
- with Sun's f77 compiler I have come across three situations (in three years)
- where the optimizer produced bad code and in one case code that would crash my
- machine. The addition of one innocuous line to a working subroutine would
- cause havoc.
-
- The solution in all three cases was to break up one of the subroutines into a
- set of smaller routines. In general, this is good programming practice but
- also helps the optimizer from becoming too cavalier with my code :-)
-