[m-dev.] Mutually recursive tailcalls in hlc.

Mark Brown mark at mercurylang.org
Fri Nov 6 23:41:05 AEDT 2015


On Fri, Nov 6, 2015 at 9:59 PM, Paul Bone <paul at bone.id.au> wrote:
> On Fri, Nov 06, 2015 at 12:35:51PM +1100, Mark Brown wrote:
>> 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.

I'd also advise checking how likely they are to extend this in future.

>
> If the C compiler cannot do this I don't see a problem with adding such a
> transformation ourselves.

If a future C compiler can do it then your efforts won't be of so much
value. And if you believe that that won't happen in the medium or long
term that raises a few more questions, which is why I asked.

It's not that I disagree with what you are proposing, I just wanted to
know more of the thinking behind it.

Mark



More information about the developers mailing list