Tail recursion

Chris Gray cg at myrias.UUCP
Thu Apr 17 02:43:24 AEST 1986


When I was playing around with a compiler (not a C compiler) for CP/M-80
I included the following peephole optimization:

	call	x	=>	jmp	x
	ret

Of course it was only done if the call wasn't preceded by a PUSH.
Unfortunately, some of the built-in constructs which required run-time
support had arguments that were pushed onto the stack at some indeterminate
time in the past. I put in some kludges to handle them (flushing the peephole
after the call), but there were still problems. In the end the amount of
kludging to get it right outweighed the benefits, so I just ripped out the
optimization.

This is a much simpler case than recognizing tail recursion, but it does
illustrate some of the things compiler writers will try to do.

			Chris Gray (ihnp4!alberta!myrias!cg)



More information about the Comp.lang.c mailing list