AMDGPU: Fix bug in r371671 on some builds.
llvm-svn: 371761
diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index 1e95cee..dad9fed 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -589,11 +589,14 @@
// Remove initializations that were merged into another.
for (auto &Init : Inits) {
auto &Defs = Init.second;
- for (auto I = Defs.begin(); I != Defs.end(); ++I)
+ auto I = Defs.begin();
+ while (I != Defs.end()) {
if (MergedInstrs.count(*I)) {
(*I)->eraseFromParent();
I = Defs.erase(I);
- }
+ } else
+ ++I;
+ }
}
// Try to schedule SGPR initializations as early as possible in the MBB.