[m-dev.] Mutually recursive tailcalls in hlc.
paul at bone.id.au
Fri Nov 6 21:59:36 AEDT 2015
On Fri, Nov 06, 2015 at 12:35:51PM +1100, Mark Brown wrote:
> On Thu, Nov 5, 2015 at 4:17 PM, Paul Bone <paul at bone.id.au> wrote:
> > The high level backends do not support optimising mutual recursion.
> The point of it being "high level" is that it generates C code that is
> much closer to what a human programmer would write. There are at least
> a few good reasons to do this:
> - C compiler optimisations are more likely to be applicable.
> - C compiler bugs are less likely to be encountered.
> - Users sometimes need to read the generated code.
> On the face of it, this optimisation is the C compiler's
> responsibility. So I don't think you should even begin measuring
> things until you say why you believe this won't happen.
> Are there any circumstances in which gcc can, in fact, optimise mutual
> tail recursion?
I'll investigate this. I recall Peter W saying in a YesLogic meeting that
mutual recursion is only optimized when the frame sizes of the mutually
recursive C functions' stack frames are identical.
If the C compiler cannot do this I don't see a problem with adding such a
transformation ourselves. To address your points above.
More information about the developers