Hasty Briefsbeta

Bilingual

Matt Godbolt's blog

2 days ago
  • Tail call optimization (TCO) turns recursive functions into loops by replacing calls with jumps, saving stack space and enabling further optimizations.
  • Clang's [[clang::musttail]] attribute forces TCO, ensuring tail calls are optimized even in debug mode.
  • Arranging function arguments to match the calling convention improves TCO efficiency by reducing register shuffling.
  • In CPU emulators, TCO can replace a switch loop with separate instruction handlers, improving branch prediction by giving each handler its own predictor state.