https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90231
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Sure, the debug stmts should not have any effect on code generation. I admit I don't know much about ivopts implementation, but either when you are rewriting stmts containing uses of the IV being replaced by some other IV, don't you know an IV from the same class already and similarly to how the replacement is done for those, you'd tweak debug stmts too? And, if there aren't any normal uses (I think the only spot i_18 is used is in the increment of the iterator), can't you try to determine an IV from the same class (if it exist) and again, emit the needed expressions in debug stmts? While the debug stmts don't have a rigid shape like other GIMPLE stmts, we certainly try to avoid arbitrarily complex expressions in there, though one can use the DEBUG_EXPR_DECL temporaries. So when you for the IV i_18 being removed notice some debug uses, add something like: # DEBUG D#6 => ivtmp.11_20 - ivtmp.11_5 # DEBUG D#7 => D#6 / 4 # DEBUG D#8 => (int) D#7 and replace all debug stmt uses of i_18 with D#8.