From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,cf4ba3d07912d446 X-Google-Attributes: gid1164f8,public X-Google-Thread: 1094ba,cf4ba3d07912d446 X-Google-Attributes: gid1094ba,public From: Paul Winalski Subject: Re: Mysterious data corruption in Fortran with -automatic Date: 1998/06/08 Message-ID: <357C38B6.B9546F8@lspace.zko.dec.com>#1/1 X-Deja-AN: 360772422 Content-Transfer-Encoding: 7bit References: <01bd9013$76f09aa0$6f242499@stupidwin95> <35774C1A.2985A59E@rhea.umd.edu> <01bd9036$7ae7fea0$LocalHost@stupidwin95> Mime-Version: 1.0 To: "Kevin G. Rhoads" Content-Type: text/plain; charset=us-ascii Organization: Digital Equipment Corporation Newsgroups: comp.sys.dec,comp.lang.fortran Kevin G. Rhoads wrote: > > Please read what I wrote and respond to that. > > If the code gives CORRECT answers with compiler > optimizations OFF and it gives WRONG answers > with compiler optimizations ON -- question, where > is the bug? > > Answer, in the compiler optimizations -- the code > did NOT change, the compiler did. When a program works with optimization turned off but not when optimization is turned on, it usually means one of two things: 1) The program is an illegal program that is doing something that the language definition says is illegal or has undefined or unpredictible results. 2) The program is triggering a compiler bug. It's been my experience that the majority of "optimizer bugs" turn out to be illegal programs. It's quite easy to introduce these sorts of problems into your code. Just one small Fortran example: IF (A .NE. B) .AND. (FUNC(X, Y) .NE. 4) where FUNC is a function that, as a side effect, modifies variable Y, followed later by some code that depends on FUNC having changed Y's value as a result of the execution of the IF statement. The Fortran language does not guarantee the order of evaluation of expressions of equal precedence; the compiler is free to evaluate the comparison of A and B first and then shortcut the expression if they're equal, so that FUNC never gets called. When optimization is turned off, a simple-minded full evaluation of the expression might take place, so that the code seems to "work", but it "breaks" if you turn on optimization and the compiler decides to exercise its right not to call FUNC if it can evaluate the expression without doing so. This is a case where the code didn't change, but it is not an optimizer bug. The program is depending on a particular result from an operation that is defined in the language as being unpredictible. --PSW