GVN: tolerate an instruction being replaced without existing in the leaderboard
[oota-llvm.git] / lib / Transforms / Scalar / GVN.cpp
index 2c47a8ab78385a6dfa874f053d8c1faeb1b39bb3..b1a0db356a1e0a2ffb6807d946b7026f9eb952a8 100644 (file)
@@ -656,11 +656,14 @@ namespace {
       LeaderTableEntry* Prev = nullptr;
       LeaderTableEntry* Curr = &LeaderTable[N];
 
-      while (Curr->Val != I || Curr->BB != BB) {
+      while (Curr && (Curr->Val != I || Curr->BB != BB)) {
         Prev = Curr;
         Curr = Curr->Next;
       }
 
+      if (!Curr)
+        return;
+
       if (Prev) {
         Prev->Next = Curr->Next;
       } else {