reduce redundancy in the hashing code and other misc cleanups.
authorChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 01:10:08 +0000 (01:10 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Jan 2011 01:10:08 +0000 (01:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122720 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/EarlyCSE.cpp
lib/Transforms/Scalar/LoopIdiomRecognize.cpp

index 80daa5a4c6629e64a939bffe8bd04f6c41882ef1..4399e2ee1fda5f2dda4e15b6d5e5e6330cd7d632 100644 (file)
@@ -18,7 +18,6 @@
 #include "llvm/Pass.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Analysis/InstructionSimplify.h"
-#include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Support/Debug.h"
@@ -80,28 +79,33 @@ unsigned getHash(const void *V) {
 
 unsigned DenseMapInfo<InstValue>::getHashValue(InstValue 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)
+    Res ^= getHash(Inst->getOperand(i)) << i;
+
   if (CastInst *CI = dyn_cast<CastInst>(Inst))
-    Res = getHash(CI->getOperand(0)) ^ getHash(CI->getType());
-  else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Inst))
-    Res = getHash(BO->getOperand(0)) ^ (getHash(BO->getOperand(1)) << 1);
-  else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
-    Res = getHash(GEP->getOperand(0));
-    for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
-      Res ^= getHash(GEP->getOperand(i)) << i;
-  } else if (CmpInst *CI = dyn_cast<CmpInst>(Inst)) {
-      Res = getHash(CI->getOperand(0)) ^ (getHash(CI->getOperand(1)) << 1) ^
-         CI->getPredicate();
+    Res ^= getHash(CI->getType());
+  else if (CmpInst *CI = dyn_cast<CmpInst>(Inst))
+    Res ^= CI->getPredicate();
+  else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Inst)) {
+    for (ExtractValueInst::idx_iterator I = EVI->idx_begin(),
+         E = EVI->idx_end(); I != E; ++I)
+      Res ^= *I;
+  } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(Inst)) {
+    for (InsertValueInst::idx_iterator I = IVI->idx_begin(),
+         E = IVI->idx_end(); I != E; ++I)
+      Res ^= *I;
   } else {
-    assert((isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
-            isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
-            isa<ExtractValueInst>(Inst) || isa<InsertValueInst>(Inst)) &&
-           "Unhandled instruction kind");
-    Res = getHash(Inst->getType()) << 4;
-    for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
-      Res ^= getHash(Inst->getOperand(i)) << i;
+    // nothing extra to hash in.
+    assert((isa<BinaryOperator>(Inst) || isa<GetElementPtrInst>(Inst) ||
+            isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
+            isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst)) &&
+           "Invalid/unknown instruction");
   }
-  
+
+  // Mix in the opcode.
   return (Res << 1) ^ Inst->getOpcode();
 }
 
index 086afb14b29996398f11e555f827cf8cd639dbeb..dc55848d35f10e1f7fc2d80e8fbd46cafdf247ac 100644 (file)
@@ -32,7 +32,7 @@
 //     for (i) { __real__(*P) = 0;  __imag__(*P) = 0; }
 // this is also "Example 2" from http://blog.regehr.org/archives/320
 //
-// This could regognize common matrix multiplies and dot product idioms and
+// This could recognize common matrix multiplies and dot product idioms and
 // replace them with calls to BLAS (if linked in??).
 //
 //===----------------------------------------------------------------------===//