> I think the ultimate knowledge if a call can or cannot be implemented as > tail-call lies within calls.cc/expand_call: It is inherently > target and ABI specific how arguments and returns are layed out, how the > stack frame is generated, if arguments are or aren't removed by callers > or callees and so on; all of that being knowledge that tree-tailcall > doesn't have and doesn't want to have. As such tree-tailcall should > not be regarded as ultimate truth, and failures of tree-tailcall to > recognize something as tail-callable shouldn't matter.
It's not the ultimate truth, but some of the checks it does are not duplicated at expand time nor the backend. So it's one necessary pre condition with the current code base. Yes maybe the checks could be all moved, but that's a much larger project. -Andi