diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1312,48 +1312,26 @@ bool loopIsFiniteByAssumption(const Loop *L); class FoldID { - SmallVector Bits; + const SCEV *Op = nullptr; + const Type *Ty = nullptr; + unsigned short C; public: - void addInteger(unsigned long I) { - if (sizeof(long) == sizeof(int)) - addInteger(unsigned(I)); - else if (sizeof(long) == sizeof(long long)) - addInteger((unsigned long long)I); - else - llvm_unreachable("unexpected sizeof(long)"); + FoldID(SCEVTypes C, const SCEV *Op, const Type *Ty) : Op(Op), Ty(Ty), C(C) { + assert(Op); + assert(Ty); } - void addInteger(unsigned I) { Bits.push_back(I); } - void addInteger(int I) { Bits.push_back(I); } - void addInteger(unsigned long long I) { - addInteger(unsigned(I)); - addInteger(unsigned(I >> 32)); - } - - void addPointer(const void *Ptr) { - // Note: this adds pointers to the hash using sizes and endianness that - // depend on the host. It doesn't matter, however, because hashing on - // pointer values is inherently unstable. Nothing should depend on the - // ordering of nodes in the folding set. - static_assert(sizeof(uintptr_t) <= sizeof(unsigned long long), - "unexpected pointer size"); - addInteger(reinterpret_cast(Ptr)); - } + FoldID(unsigned short C) : C(C) {} unsigned computeHash() const { - unsigned Hash = Bits.size(); - for (unsigned I = 0; I != Bits.size(); ++I) - Hash = detail::combineHashValue(Hash, Bits[I]); - return Hash; + return detail::combineHashValue( + C, detail::combineHashValue(reinterpret_cast(Op), + reinterpret_cast(Ty))); } + bool operator==(const FoldID &RHS) const { - if (Bits.size() != RHS.Bits.size()) - return false; - for (unsigned I = 0; I != Bits.size(); ++I) - if (Bits[I] != RHS.Bits[I]) - return false; - return true; + return std::tie(Op, Ty, C) == std::tie(RHS.Op, RHS.Ty, RHS.C); } }; @@ -2394,13 +2372,11 @@ template <> struct DenseMapInfo { static inline ScalarEvolution::FoldID getEmptyKey() { - ScalarEvolution::FoldID ID; - ID.addInteger(~0ULL); + ScalarEvolution::FoldID ID(0); return ID; } static inline ScalarEvolution::FoldID getTombstoneKey() { - ScalarEvolution::FoldID ID; - ID.addInteger(~0ULL - 1ULL); + ScalarEvolution::FoldID ID(1); return ID; } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -1551,10 +1551,7 @@ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!"); Ty = getEffectiveSCEVType(Ty); - FoldID ID; - ID.addInteger(scZeroExtend); - ID.addPointer(Op); - ID.addPointer(Ty); + FoldID ID(scZeroExtend, Op, Ty); auto Iter = FoldCache.find(ID); if (Iter != FoldCache.end()) return Iter->second; @@ -1890,10 +1887,7 @@ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!"); Ty = getEffectiveSCEVType(Ty); - FoldID ID; - ID.addInteger(scSignExtend); - ID.addPointer(Op); - ID.addPointer(Ty); + FoldID ID(scSignExtend, Op, Ty); auto Iter = FoldCache.find(ID); if (Iter != FoldCache.end()) return Iter->second;