Several for loops in PromoteMemoryToRegister.cpp leave their increment
expression empty, instead incrementing the iterator within the for loop
body. I believe this is because these loops were previously implemented
as while loops; see https://reviews.llvm.org/rL188327.
Incrementing the iterator within the body of the for loop instead of
in its increment expression makes it seem like the iterator will be
modified or conditionally incremented within the loop, but that is not
the case in these loops.
Instead, use range loops.
Test Plan: check-llvm
I think the old code was more safe since it does not depend as much on how the iterators are implemented. The instruction "I" is actually deleted inside the loop. So stepping the iterator after deleting "I" could be dangerous if stepping of the iterator involves dereferencing of the object that the iterator refers. Or am I missing something?
I would at least assume that the old code was written the way it was just because the datastructure that we iterate over can change during iteration. So it should be more safe to step the iterator to the "next" element first, and then remove the "current" element.