C "optimization" (5 of 8)

Dan Klein dvk at mi-cec.UUCP
Wed Feb 15 05:24:36 AEST 1984


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



More information about the Comp.lang.c mailing list