home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4405 < prev    next >
Encoding:
Internet Message Format  |  1992-11-22  |  3.0 KB

  1. Path: sparky!uunet!think.com!ames!agate!agate.berkeley.edu!dodd
  2. From: dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Legal optimization?
  5. Date: 22 Nov 92 06:56:07
  6. Organization: Dept of Chemical Engineering, Polytechnic Univ, NY, USA
  7. Lines: 45
  8. Message-ID: <DODD.92Nov22065607@mycenae.cchem.berkeley.edu>
  9. References: <1992Nov21.114131.24902@alf.uib.no>
  10. Reply-To: dodd@roebling.poly.edu
  11. NNTP-Posting-Host: mycenae.cchem.berkeley.edu
  12. In-reply-to: iversen@dsfys1.fi.uib.no's message of Sat, 21 Nov 92 11:41:31 GMT
  13.  
  14.  
  15. >>>>> "Per" == Per Steinar Iversen <iversen@vsfys1.fi.uib.no> writes:
  16.  
  17.   Per> One of the students here uses VAX FORTRAN to calculate various things for his
  18.   Per> thesis. Recently he had some problems, which were traced down to a real bug.
  19.   Per> However: A result of the bug was that a square root of a negative REAL occurred.
  20.   Per> Yet this never made the program crash! When either a WRITE statement was 
  21.   Per> inserted on the next line after the SQRT or the optimization was turned off,
  22.   Per> then the program crashed properly... Presumably the optimizer transforms the
  23.   Per> code into something which is OK if the values are *not* negative. At least in 
  24.   Per> this program however the results were just garbage if the negative root occurred.
  25.  
  26.   Per> The compiler is VAX FORTRAN V5.8-155 under VMS 5.5. So far I always felt safe
  27.   Per> if my programs compiled and ran with 
  28.   Per> FORTRAN/CHECK=ALL/STANDARD=ALL/WARNING=(GENERAL,DECLARATIONS), but I guess I
  29.   Per> should add /NOOPTIMIZE too.
  30.  
  31.   Per> My question is more philosophical perhaps: Are such transformations of the 
  32.   Per> code actually legal, is the compiler performing within the standard?
  33.  
  34. Welcome to the world of code optimization!  I don't think that the standard
  35. has any meaning once the optimizer has gotten hold of it. Rule: the optimizer
  36. is only as good as the person that wrote it. Some of them are damn good.  Most
  37. are good at local 10-20 line optimization.  It is when higher level
  38. optimization (i.e., so-called global optimization and inlining) is attempted
  39. that things can go wrong.
  40.  
  41. Two things that I do to stop the optimizer from screwing me:
  42.  
  43.   (1) compile and run with and without the optimizer -- obviously, the results
  44.       should be identical -- with unix f77 this can be done with -g typically
  45.       without any -O[1234].
  46.  
  47.   (2) Keep sub-programs small. This lessens the chance of the optimizer from
  48.       assuming too much.  
  49.  
  50. I used VMS for five years and discovered no real `bugs' in the optimizer but
  51. with Sun's f77 compiler I have come across three situations (in three years)
  52. where the optimizer produced bad code and in one case code that would crash my
  53. machine.  The addition of one innocuous line to a working subroutine would
  54. cause havoc.
  55.  
  56. The solution in all three cases was to break up one of the subroutines into a
  57. set of smaller routines.  In general, this is good programming practice but
  58. also helps the optimizer from becoming too cavalier with my code :-)
  59.