[llvm] 6b5ce0d - [InstCombine] Fix removal from deferred instructions

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 08:48:38 PST 2020


Author: Nikita Popov
Date: 2020-02-19T17:48:28+01:00
New Revision: 6b5ce0de7e57cbb37c7a03e216c779ed4073ad2e

URL: https://github.com/llvm/llvm-project/commit/6b5ce0de7e57cbb37c7a03e216c779ed4073ad2e
DIFF: https://github.com/llvm/llvm-project/commit/6b5ce0de7e57cbb37c7a03e216c779ed4073ad2e.diff

LOG: [InstCombine] Fix removal from deferred instructions

Make sure we don't skip the Deferred.remove() call if the
instruction is not in the worklist. Both of those are separate.

We don't have any cases where deferred instructions get removed
right now, but may cause problems in the future.

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h b/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
index 1a2a15e89954..f019bb5ecf39 100644
--- a/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
+++ b/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
@@ -97,12 +97,12 @@ class InstCombineWorklist {
   /// Remove I from the worklist if it exists.
   void remove(Instruction *I) {
     DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
-    if (It == WorklistMap.end()) return; // Not in worklist.
-
-    // Don't bother moving everything down, just null out the slot.
-    Worklist[It->second] = nullptr;
+    if (It != WorklistMap.end()) {
+      // Don't bother moving everything down, just null out the slot.
+      Worklist[It->second] = nullptr;
+      WorklistMap.erase(It);
+    }
 
-    WorklistMap.erase(It);
     Deferred.remove(I);
   }
 


        


More information about the llvm-commits mailing list