This is a difficult problem.
All the phi placement algorithms I know of run in linear time per variable. The problem is there are O(n) variables. That leads to quadratic behavior.
Pruned ssa form, which gets rid of dead phis, would help. But the only way I know to do that is to compute live variables first. But that in itself can lead to quadratic behavior. (It would fix this example, though.)
I would love to have a phi placement algorithm that ran in O(n) time in the size of the minimal output, full stop. I don't think such a thing is known to exist.
I've been thinking about how to avoid placing phis outside the union of the subtrees dominated by the variable definitions. It would probably help this case. Definitely not for 1.8 though.
Algorithmic improvements here are hard.
Lifting a lookup out of the loop helps a little, though.
To compile the code in #17926:
name old s/op new s/op delta
Real 146 ± 3% 140 ± 4% -3.87% (p=0.002 n=10+10)
User 143 ± 3% 139 ± 4% -3.08% (p=0.005 n=10+10)
Sys 8.28 ±35% 8.08 ±28% ~ (p=0.684 n=10+10)
Run-TryBot: Josh Bleecher Snyder <email@example.com>
TryBot-Result: Gobot Gobot <firstname.lastname@example.org>
Reviewed-by: Keith Randall <email@example.com>