getFirstNonPHI iterates over all the instructions in a block until it finds a non-PHI.
Then, the loop starts from the beginning of the block and goes through all the instructions until it reaches the instruction found by getFirstNonPHI.
Instead of doing that, just stop when a non-PHI is found.
This reduces the compile-time of a test case discussed in https://reviews.llvm.org/D47023 by 13x.
Not entirely sure how to come up with a test case for this since it's a compile time issue that would significantly slow down running the tests.
Could you just use the iterator range BB->phis()? This should automatically iterate until it hits a non-phi instruction.