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

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!cs.utexas.edu!tamsun.tamu.edu!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!burley
  2. From: burley@apple-gunkies.gnu.ai.mit.edu (Craig Burley)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: Legal optimization?
  5. Date: 23 Nov 92 10:58:53
  6. Organization: Free Software Foundation 545 Tech Square Cambridge, MA 02139
  7. Lines: 52
  8. Message-ID: <BURLEY.92Nov23105853@apple-gunkies.gnu.ai.mit.edu>
  9. References: <1992Nov21.114131.24902@alf.uib.no>
  10.     <DODD.92Nov22065607@mycenae.cchem.berkeley.edu>
  11. NNTP-Posting-Host: apple-gunkies.gnu.ai.mit.edu
  12. In-reply-to: dodd@mycenae.cchem.berkeley.edu's message of 22 Nov 92 06:56:07
  13.  
  14. In article <DODD.92Nov22065607@mycenae.cchem.berkeley.edu> dodd@mycenae.cchem.berkeley.edu (Lawrence R. Dodd) writes:
  15.  
  16.    >>>>> "Per" == Per Steinar Iversen <iversen@vsfys1.fi.uib.no> writes:
  17.  
  18.      Per> One of the students here uses VAX FORTRAN to calculate various things for his
  19.      Per> thesis. Recently he had some problems, which were traced down to a real bug.
  20.      Per> However: A result of the bug was that a square root of a negative REAL occurred.
  21.      Per> Yet this never made the program crash! When either a WRITE statement was 
  22.      Per> inserted on the next line after the SQRT or the optimization was turned off,
  23.      Per> then the program crashed properly... Presumably the optimizer transforms the
  24.      Per> code into something which is OK if the values are *not* negative. At least in 
  25.      Per> this program however the results were just garbage if the negative root occurred.
  26.  
  27.    Welcome to the world of code optimization!  I don't think that the standard
  28.    has any meaning once the optimizer has gotten hold of it. Rule: the optimizer
  29.    is only as good as the person that wrote it. Some of them are damn good.  Most
  30.    are good at local 10-20 line optimization.  It is when higher level
  31.    optimization (i.e., so-called global optimization and inlining) is attempted
  32.    that things can go wrong.
  33.  
  34.    The solution in all three cases was to break up one of the subroutines into a
  35.    set of smaller routines.  In general, this is good programming practice but
  36.    also helps the optimizer from becoming too cavalier with my code :-)
  37.  
  38. Actually, the problem is not with the optimization, but with the code
  39. you're feeding to it.  More precisely, instead of "I don't think the standard
  40. has any meaning once the optimizer has gotten ahold of it", the truth of
  41. the matter is this:
  42.  
  43.     The standard has no meaning once nonconforming code is involved.
  44.     (Aside from stating that it has no meaning, i.e. that the results
  45.     are "undefined".  Note that the Fortran 90 standard actually tries
  46.     to give itself some meaning as far as insisting that some cases of
  47.     nonconforming code be diagnosed, but those are, I think, pretty much
  48.     all cases of diagnosis at what we think of as compile time, not
  49.     run-time cases like SQRT of a negative number.)
  50.  
  51. It's nice that a system diagnose programmer errors whenever it can, but
  52. it's even nicer when it stops doing that when you specify -O[something]
  53. and the cost of diagnosis vs. just assuming the program is correct is
  54. nonzero.
  55.  
  56. Certainly there have been optimizers and optimizations that make code run
  57. faster assuming that certain ordinarily conforming activities aren't
  58. undertaken by the program -- and in some cases, those assumptions weren't
  59. documented or perhaps even recognized by the designers of the optimizations --
  60. but the case cited above, as far as I know, doesn't fit into these categories.
  61. It seems to me that the code was wrong, not the optimizer.
  62. --
  63.  
  64. James Craig Burley, Software Craftsperson    burley@gnu.ai.mit.edu
  65. Member of the League for Programming Freedom (LPF) lpf@uunet.uu.net
  66.