Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site lanl.ARPA Path: utzoo!utcsrgv!garfield!philabs!cmcl2!lanl!jlg From: jlg@lanl.ARPA Newsgroups: net.unix-wizards,net.lang Subject: Re: smart compilers Message-ID: <18397@lanl.ARPA> Date: Thu, 20-Dec-84 20:29:14 EST Article-I.D.: lanl.18397 Posted: Thu Dec 20 20:29:14 1984 Date-Received: Fri, 21-Dec-84 06:43:02 EST References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> Sender: newsreader@lanl.ARPA Organization: Los Alamos National Laboratory Lines: 41 > However, the IBM H Level FORTRAN Programmer's Guide does warn that code such > as > > DO 100 I = 1 TO 10 > IF (Y .GT. 0) X(I) = SQRT(Y) > 100 CONTINUE > > (with X appropriately declared as an array of course) can cause an error > because it tries to take the square root of a negative number. The optimizer > compiles this as if it were > > TEMP = SQRT(Y) > DO 100 I = 1 TO 10 > IF (Y .GT. 0) X(I) = TEMP > 100 CONTINUE This particular example should be optimized as IF ( Y.GT.0 ) TEMP=SQRT(Y) DO 100 I = 1,10 !THERE ARE NO 'TO' DELIMITERS IN FORTRAN X(I)=TEMP !FOLLOW INDENTATION STANDARDS PLEASE 100 CONTINUE A good data flow analysis would have seen this. However, in general these types of optimizations are called 'unsafe'; for obvious reasons. I don't think unsafe optimizations are allowed by the standard since they change the meaning of the code (in particular, they cause errors when none would have normally occurred). IBM has simply stepped out of line here. IBM is not alone, most vendors tend to have some violations of the standard lurking around in the compilers. The given example has a safe optimization available to it. It is possible to come up with cases that don't, so in general this sort of optimization should be considered unsafe (unless you have a really good data flow analyzer available to guarantee safety). ------------------------------------------------------------------------------ The greatest derangement of the mind is to believe in something because one wishes it to be so - Louis Pasteur James Giles