Some questions about the C -Optimiser

mckusick at ucbvax.UUCP mckusick at ucbvax.UUCP
Wed Jun 8 06:27:02 AEST 1983


The reason that the optimizer frequently "misses" oportunities
to get rid of

	someopt	src,r0
	movl	r0,dst

is because r0 is used as the return value register. If all of
these were uniformly replaced by
	
	someopt	src,dst

then statements such as

	return (a = b + 1);

that generate code as

	addl3	$1,_b,r0
	movl	r0,_a

would get optimized to

	addl3	$1,_b,_a

and would never set r0, thus returning garbage. The optimizer
takes a very pessimistic view and never optimizes away assignments
to r0 if the assignment is at the end of a basic block. The appropriate
fix would be to have the C compiler avoid using r0 as a temporary
unless it either forced to, or meant to set the return value.

	Kirk McKusick
	ucbvax!mckusick
	mckusick at berkeley



More information about the Comp.lang.c mailing list