Instead of only detecting trivial cycles which must be a PHI with a single use that's a PHI, which in turn has a single use of the first PHI, generalize it to catch more complex cycles. This means making it look through all of its uses, as well as looking through arbitrary side-effect free instructions.
The motivation behind this is to enable InstCombiner to remove larger dead PHI cycles in one iteration, to prevent cascading iterations in some pathological cases with lots of dead PHI cycles.
Supersedes D142293
Fixes https://github.com/llvm/llvm-project/issues/50564
This code should also run for non-phis, with PotentiallyDeadPHIs -> PotentiallyDeadInsts. We want to count non-phi instructions towards the limit as well. I expect this is why you're seeing such a large compile time impact, because as written we only limit the number of visited phis, not the number of visited instructions.