Path: utzoo!utgpu!water!watmath!clyde!att!att-ih!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c Subject: Re: Optimization (was Re: volatile) Message-ID: <4628@ihlpf.ATT.COM> Date: 4 May 88 01:01:07 GMT References: <13074@brl-adm.ARPA> <3938@killer.UUCP> <511@wsccs.UUCP> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 72 In article <511@wsccs.UUCP> terry@wsccs.UUCP (Every system needs one) writes: >I didn't say they shouldn't effect the generated program, I said that they >shouldn't effect the OPERATION of the generated program. What's the difference between your two statements? Optimizers, almost by definition, do effect the operation of the generated program. Take the following example: int bar; int foo; int temp; ... bar = temp; foo = bar; ... Unoptimized, what should this produce? Answer: something like: Take the value stored in temp Convert it to int Store it in bar Return the value stored in bar Take the value stored in bar Convert it to int Store it in foo Return the value stored in foo If *any* of these steps are skipped then I would consider that code to be optimized. Here is what optimized code might be: Take the value stored in temp Store it in foo Store it in bar Should this be an illegal optimization? No! Optimizers, in a nutshell, figure out the *results* of what you coded and then generate the best possible code to obtain those results. Optimizers need not generate code that performs all of the operations in the order that you requested them, as long as the results, for a correct program, are unchanged. Volatile is needed to stop those optimzations since, in some circumstances, it is required that none of the intermediate operations can be skipped because outside forces may change some of the variables between operations. The problem I have with volatile, as it is defined now, is that it doesn't really say which optimizations are allowed and which aren't (and yes, I have read footnote 52 in the Jan 88 dpANS; this statement is not good enough). In my unoptimized example, assuming all the variables were declared volatile, which statements can be legally taken out? Am I allowed to get rid of the 'return the value stored in xxx' since this value is never used? I don't know. Also, the augmented assignment operators used with volatile variables since in order to use them properly I need to know how many real machine-level references are made to the volatile variable and if the whole variable is loaded into memory at once (in the case of a volatile struct, for instance). The semantics for volatile seem to be ill-defined, at best. -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_