[PATCH] D131034: [Backend][X86] Improved tail call optimization for functions marked as musttail

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 12:38:02 PDT 2022


huangjd added a comment.

@efriedma This is a limitation of the current patch that it could only handle the case with arguments in matching order. After some investigation I found that the current function call lowering pass cannot handle in-place stack argument shuffling at all, as it doesn't take read/write dependency into account. It would require an extensive refactoring to completely fix it.

In addition, shuffling large stack arguments to force a tail call can get quite complicated, for instance, if we have F(x0, x1, x2, ... xn) calling G(x1, x2, ... xn, x0) where every argument is the same type and is passed by stack, in order to do an in-place argument swapping without further stack spill, the optimal code should be something like

  for i in 0..k:
    tmpreg = x0.word_i
    x0.word_i = x1.word_i
    ...
    xn.word_i = tmpreg

where word_i are cache-line sized partitions of the argument.

The current patch is able to handle two common real world scenario of tail calls (a) a function that simply delegates to another function without doing anything else, and (b) recursive tail call where only the induction variable passed by register changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131034/new/

https://reviews.llvm.org/D131034



More information about the llvm-commits mailing list