[llvm-commits] [llvm] r122720 - in /llvm/trunk/lib/Transforms/Scalar: EarlyCSE.cpp LoopIdiomRecognize.cpp

Nick Lewycky nicholas at mxc.ca
Sun Jan 2 17:21:03 PST 2011


On 01/02/2011 05:10 PM, Chris Lattner wrote:
> Author: lattner
> Date: Sun Jan  2 19:10:08 2011
> New Revision: 122720
>
> URL: http://llvm.org/viewvc/llvm-project?rev=122720&view=rev
> Log:
> reduce redundancy in the hashing code and other misc cleanups.
>
> Modified:
>      llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
>      llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp?rev=122720&r1=122719&r2=122720&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp Sun Jan  2 19:10:08 2011
> @@ -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 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();

Chris, did you consider using a FoldingSetNodeID to calculate your hash? 
I think it would end up cleaner.

Nick

>   }
>
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp?rev=122720&r1=122719&r2=122720&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LoopIdiomRecognize.cpp Sun Jan  2 19:10:08 2011
> @@ -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??).
>   //
>   //===----------------------------------------------------------------------===//
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list