[BDCE] Don't forget uses of root instructions seen before the instruction itself
[oota-llvm.git] / lib / Transforms / Scalar / BDCE.cpp
index afe0cd13e2296ce5fd7ac382b95ac16916c4b58d..e5a7ad6388d8d7aecb3e77c95651b784ce6321f6 100644 (file)
@@ -277,13 +277,17 @@ bool BDCE::runOnFunction(Function& F) {
     if (!isAlwaysLive(&I))
       continue;
 
+    DEBUG(dbgs() << "BDCE: Root: " << I);
     // For integer-valued instructions, set up an initial empty set of alive
     // bits and add the instruction to the work list. For other instructions
     // add their operands to the work list (for integer values operands, mark
     // all bits as live).
     if (IntegerType *IT = dyn_cast<IntegerType>(I.getType())) {
-      AliveBits[&I] = APInt(IT->getBitWidth(), 0);
-      Worklist.push_back(&I);
+      if (!AliveBits.count(&I)) {
+        AliveBits[&I] = APInt(IT->getBitWidth(), 0);
+        Worklist.push_back(&I);
+      }
+
       continue;
     }
 
@@ -388,7 +392,6 @@ bool BDCE::runOnFunction(Function& F) {
     if (isAlwaysLive(&I))
       continue;
 
-    DEBUG(dbgs() << "BDCE: Removing: " << I << " (unused)\n");
     Worklist.push_back(&I);
     I.dropAllReferences();
     Changed = true;