Loopification using join points
This is the master ticket for doing loopification in Core. See also:
-
Note [Self-recursive tail calls]
in GHC.StgToCmm.Expr - See wiki page: https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/loopification#new-idea-use-join-points
- #22227 has several examples of the value of loopification in Core
- #13966
- #14287
- See #14068 (comment 140494) for a wrinkle.
- See #22227 (comment 457985) for another wrinkle
The idea
The function
let f x y = case y of
A -> f x' y'
B -> e2
C -> e3
in g f
is not turned into a recursive join point, because the call to f
is not in tail call position. But the recursive calls are, and these matter performance-wise! Hence, it would be beneficial to turn this into
let f x y = joinrec $j x y = case x y of
A -> $j x' y'
B -> e2
C -> e3
in $j x y
in g f
This has the additional effect that now f
is no longer recursive and may get inlined.
The idea is described under "New idea: use join points" in Commentary/Compiler/Loopification.
Some notes:
- We should to this both at top level and for nested definitions.
- We can remove the "loopification" code from the code generator when this is done.
- It came up in #13966, and might go well with #14067.
- It might work well with #13051, which Thomas Jakway is still thinking about.
- Should fix #14287 too.
- See also ticket:14068#comment:140494 of #14620, for a wrinkle.