The backstory here is that the LCSSA invalidation we perform here is not really necessary from a SCEV perspective. However, other code may rely on the fact that invalidating only LCSSA phi nodes is sufficient for transforms like loop peeling (see https://reviews.llvm.org/D149331#4398582 for more details).
However, performing invalidation during LCSSA construction also means that SCEV expansion (which may need to construct LCSSA) can invalidate SCEV, which is somewhat unexpected and code may not be prepared to deal with it (see the added test case, reported at https://reviews.llvm.org/D149435#4428219).
Instead of invalidating SCEV, ensure that the LCSSA phi node also has cached SCEV if the original instruction did. This means that later invalidation of LCSSA phi nodes will work as expected. This should avoid both the above issues and be more efficient.