https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90231
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think the order doesn't matter in this case, as debug stmts can't have PHIs ATM and that is what you either immediately or soonish end up with. The only thing it changes is IMHO whether the D#1 appears in there or whether the second DEBUG i => is reset immediately, if you remove from end to start of the bb, then you first create D#1 that is the phi result + const and then reset that as it still refers to the PHI result, otherwise if you first remove the PHI result, you just reset whatever it refers to it. The point is that ivopts knows better and should before the removal of the IV remap it in debug stmt to something else.