stength reduce my previous patch a bit. The only instructions
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 18:43:03 +0000 (18:43 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 18:43:03 +0000 (18:43 +0000)
that are allowed to have metadata operands are intrinsic calls,
and the only ones that take metadata currently return void.
Just reject all void instructions, which should not be value
numbered anyway.  To future proof things, add an assert to the
getHashValue impl for calls to check that metadata operands
aren't present.

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

lib/Transforms/Scalar/EarlyCSE.cpp

index 61830e02d6ceaf7a47728eb09c1e0502130a97c8..6c2ea39896a682ae6815588afd5a211d452531d5 100644 (file)
@@ -145,14 +145,13 @@ namespace {
     }
     
     static bool canHandle(Instruction *Inst) {
+      // Don't value number anything that returns void.
+      if (Inst->getType()->isVoidTy())
+        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;
     }
   };
@@ -179,8 +178,12 @@ unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
   Instruction *Inst = Val.Inst;
   // Hash in all of the operands as pointers.
   unsigned Res = 0;
-  for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
+  for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i) {
+    assert(!Inst->getOperand(i)->getType()->isMetadataTy() &&
+           "Cannot value number calls with metadata operands");
     Res ^= getHash(Inst->getOperand(i)) << i;
+  }
+  
   // Mix in the opcode.
   return (Res << 1) ^ Inst->getOpcode();
 }