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 @@ -1297,48 +1297,21 @@ bool loopIsFiniteByAssumption(const Loop *L); class FoldID { - SmallVector Bits; + PointerIntPair Op; + PointerIntPair Ty; 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)"); - } - 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(SCEVTypes C, const SCEV *O, const Type *T) + : Op(O, C / 8), Ty(T, C % 8) { } 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( + reinterpret_cast(Op.getOpaqueValue()), + reinterpret_cast(Ty.getOpaqueValue())); } + 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(Ty, Op) == std::tie(RHS.Ty, RHS.Op); } }; @@ -2371,14 +2344,12 @@ template <> struct DenseMapInfo { static inline ScalarEvolution::FoldID getEmptyKey() { - ScalarEvolution::FoldID ID; - ID.addInteger(~0ULL); - return ID; + ScalarEvolution::FoldID ID(SCEVTypes(64 - 1), nullptr, nullptr); + return ID; } static inline ScalarEvolution::FoldID getTombstoneKey() { - ScalarEvolution::FoldID ID; - ID.addInteger(~0ULL - 1ULL); - return ID; + ScalarEvolution::FoldID ID(SCEVTypes(64 - 2), nullptr, nullptr); + return ID; } static unsigned getHashValue(const ScalarEvolution::FoldID &Val) { 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 @@ -1614,10 +1614,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; @@ -1936,10 +1933,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;