fix PR8895: metadata operands don't have a strong use of their
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 18:28:15 +0000 (18:28 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 18:28:15 +0000 (18:28 +0000)
nested values, so they can change and drop to null, which can
change the hash and cause havok.

It turns out that it isn't a good idea to value number stuff
with metadata operands anyway, so... don't.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122758 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/EarlyCSE.cpp

index 9e7092bacda24c1831172d4154a7beb67aecdf98..61830e02d6ceaf7a47728eb09c1e0502130a97c8 100644 (file)
@@ -145,9 +145,15 @@ namespace {
     }
     
     static bool canHandle(Instruction *Inst) {
-      if (CallInst *CI = dyn_cast<CallInst>(Inst))
-        return CI->onlyReadsMemory();
-      return false;
+      CallInst *CI = dyn_cast<CallInst>(Inst);
+      if (CI == 0 || !CI->onlyReadsMemory())
+        return false;
+      
+      // Check that there are no metadata operands.
+      for (unsigned i = 0, e = CI->getNumOperands(); i != e; ++i)
+        if (CI->getOperand(i)->getType()->isMetadataTy())
+          return false;
+      return true;
     }
   };
 }
@@ -407,7 +413,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
         if (LastStore &&
             LastStore->getPointerOperand() == SI->getPointerOperand()) {
           DEBUG(dbgs() << "EarlyCSE DEAD STORE: " << *LastStore << "  due to: "
-                << *Inst << '\n');
+                       << *Inst << '\n');
           LastStore->eraseFromParent();
           Changed = true;
           ++NumDSE;