If a phi node has one use, and that user has only one use itself, and
that one use is in turn the phi node, then the phi node is erased.
Simultaneously, whenever an instruction is erased, its operands are
added to the worklist as their use counts have changed.
But it's possible that the operand now only has one use and that use is
a phi node: So add the phi node to worklist so the phi node elimination
can occur.
This prevents the need to do lots of cascading iterations over a
function when eliminating phi nodes unlocks more potential phi node
eliminations.
Fixes #50564
Will this cause much extra work?
It certainly improves the pathological case in https://github.com/llvm/llvm-project/issues/50564, but not sure how this affects day to day cases.
The PHI node elimination that kicks in is at InstCombinePHI.cpp:1439
Another possible idea could be to somehow invert this and instead check on every instruction if it has one use that's a phi node.