Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!exodus!exodus-bb!khb From: khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) Newsgroups: comp.sys.hp Subject: Re: C Compiler Optimizer Message-ID: Date: 30 Aug 90 18:34:41 GMT References: <59169@bbn.BBN.COM> <570@dptechno.UUCP> Sender: news@exodus.Eng.Sun.COM Organization: Sun MegaSystems Lines: 59 In-reply-to: dave@dptechno.UUCP's message of 28 Aug 90 18:08:27 GMT In article <570@dptechno.UUCP> dave@dptechno.UUCP (Dave Lee) writes: It is exactly this type of hard to find infrequent optimization bugs that make ANY optimization useless. I am just too afraid of this type of bug that we CANT afford to chance it. Much Much Much better a slower On some machines (e.g. a Cray) not optimizing the code can cost a factor of about 50x. There is no point in buying a high performance computer to run slowly. The vast majority of "optimizer" bugs eventually lead back to errors in the application source code. Make sure your code passes lint (or the equivalent thereof). Then, for large projects: 1) compile at low optimization (often the default on non-unix boxes; unix traditional default is none; other platforms default to max; ibm mainframes are site specific, it is governed by the sysadmin) 2) profile 3) turn on full optimization on the most expensive module(s) 4) test and return to step 2 until happy. This heuristic works well on a wide variety of platforms. I first got into it working with old CDC machines ... they had a delightful "unsafe" optimization level (0 debugging, 1, 2, 3, u). When I finally found the module which wouldn't execute reliably at anything but 0 ... I found a minor violation of the Fortran standard ..... the code worked correctly on VAXen, IBM (levels G, H, and VS) DG's, Primes, PC's, Univacs and a dozen other platforms. Was the CDC broken ? No, it did the best optimization of the bunch. Getting the heuristic down was worth the suffering though. On modern machines, defeating ALL optimization is good for at least a factor of 2x. As more and more machines get interesting, the 50x cost will become common rather than the exception. I have seen 200x in extreme cases. Note: It is vital to realize that just because you didn't ask for optimization that doesn't mean you didn't get it. Example: The LPI compiler on SPARCs default to its max optimization level. The Sun compiler defaults to none. This does not represent varying degrees of trust, it represent variant traditions. The unix tradition is for all "tools" to do something simple and to have an array of options ... which users are expected to "softwire" with shell magic. LPI's tradition comes from a traditional minicomputerish (nonunix) realm... When working on machines like the VAX, where optimization only provided a 30% boost being a neoluddite wasn't so expensive. Nowadays it can be a very, very expensive vice. -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043