Revert "[BDCE][DemandedBits] Detect dead uses of undead instructions"

This reverts commit r349674. It causes a failure in
test-suite enc-3des.execution_time.

llvm-svn: 349684
diff --git a/llvm/lib/Transforms/Scalar/BDCE.cpp b/llvm/lib/Transforms/Scalar/BDCE.cpp
index 65a68c1..f63182e 100644
--- a/llvm/lib/Transforms/Scalar/BDCE.cpp
+++ b/llvm/lib/Transforms/Scalar/BDCE.cpp
@@ -96,38 +96,30 @@
     if (I.mayHaveSideEffects() && I.use_empty())
       continue;
 
-    // Remove instructions not reached during analysis.
-    if (DB.isInstructionDead(&I)) {
-      salvageDebugInfo(I);
-      Worklist.push_back(&I);
-      I.dropAllReferences();
-      Changed = true;
-      continue;
-    }
-
-    for (Use &U : I.operands()) {
-      // DemandedBits only detects dead integer uses.
-      if (!U->getType()->isIntOrIntVectorTy())
-        continue;
-
-      // TODO: We could also find dead non-instruction uses, e.g. arguments.
-      if (!isa<Instruction>(U))
-        continue;
-
-      if (!DB.isUseDead(&U))
-        continue;
-
-      LLVM_DEBUG(dbgs() << "BDCE: Trivializing: " << U << " (all bits dead)\n");
+    if (I.getType()->isIntOrIntVectorTy() &&
+        !DB.getDemandedBits(&I).getBoolValue()) {
+      // For live instructions that have all dead bits, first make them dead by
+      // replacing all uses with something else. Then, if they don't need to
+      // remain live (because they have side effects, etc.) we can remove them.
+      LLVM_DEBUG(dbgs() << "BDCE: Trivializing: " << I << " (all bits dead)\n");
 
       clearAssumptionsOfUsers(&I, DB);
 
       // FIXME: In theory we could substitute undef here instead of zero.
       // This should be reconsidered once we settle on the semantics of
       // undef, poison, etc.
-      U.set(ConstantInt::get(U->getType(), 0));
+      Value *Zero = ConstantInt::get(I.getType(), 0);
       ++NumSimplified;
+      I.replaceNonMetadataUsesWith(Zero);
       Changed = true;
     }
+    if (!DB.isInstructionDead(&I))
+      continue;
+
+    salvageDebugInfo(I);
+    Worklist.push_back(&I);
+    I.dropAllReferences();
+    Changed = true;
   }
 
   for (Instruction *&I : Worklist) {