Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!akgua!mcnc!idis!mi-cec!dvk From: dvk@mi-cec.UUCP (Dan Klein) Newsgroups: net.lang.c Subject: C "optimization" (5 of 8) Message-ID: <207@mi-cec.UUCP> Date: Tue, 14-Feb-84 14:24:36 EST Article-I.D.: mi-cec.207 Posted: Tue Feb 14 14:24:36 1984 Date-Received: Fri, 17-Feb-84 04:24:10 EST Lines: 47 This is a continuation of my diatribe on "C doesn't optimize, it neatens". In this and other articles, I compare a true optimizing compiler (Bliss-32 running under VMS) to a code neatener (C running under BSD 4.1c). Any and all counterexamples are welcome. However, this is NOT a comparison of the languages. Both C and Bliss have their good and bad points. This is simply a comparison of the code they generate. As in all examples, the source code and uncensored assembly code is presented. In all examples, the C source and Bliss source are as nearly identical as language differences permit. I have not taken advantage of any "tricks" to get either language to perform better or worse than the other. The optimizer was enabled for both languages. -Dan Klein, Mellon Institute, Pittsburgh (412)578-3382 ============================================================================= In this example I show what the compilers do when they find unused local variables. Simply put, if a local variable is unused, there is no reason to allocate space for it. The time spent allocating space is a waste. The Bliss compiler knows that both "a" and "b" are not used, so no space is reserved for them. The C compiler on the other hand subtracts 8 from the stack pointer, and then does not touch the space. Why bother? (The debugger can always be told the variable is not allocated). The removal of unused locals should be a transparent operation. Instead, the C compiler needs the help of "lint" to warn you about it. Bogus! ----------------------------------------+------------------------------------- external routine alpha; | extern alpha(); | routine test(parm) : NoValue = | test(parm) begin | { local a,b; | int a, b; | alpha(.parm); | alpha(parm); end; | } | | .TITLE FOO | .data | .text .EXTRN ALPHA | LL0: .align 1 | .globl _test .PSECT $CODE$,NOWRT,2 | .set L13,0x0 | .data TEST: .WORD ^M<> | .text PUSHL 4(AP) | _test: .word L13 CALLS #1, W^ALPHA | subl2 $8,sp RET | pushl 4(ap) | calls $1,_alpha | ret