Elektrine lite

← Feed

@nrab@hachyderm.io

Post #2639723

2025-05-17 09:23 UTC

@porglezomp@mastodon.social @ela@infosec.exchange you start with the tail recursion optimization but here isEven is very clearly not tail recursive. Do you know how LLVM handles that?

Replies (1)

  • @ela@infosec.exchange 2025-05-17 10:38

    @nrab@hachyderm.io @porglezomp@mastodon.social LLVM extends that basic algorithm a tad bit by trying to move instructions between the call and the return to the top of the generated loop. In cases in which this isn't trivially true (like for code neither depending on the function call value nor having an influence on the return value), there is one additional trick. If the operation performed on the return value of the function call is a commutative and associative operation, it can be eliminated using accumulator recursion elimination. The code lives here: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp#L658

    Open ##2639724