[llvm] [CodeGen][Transforms] Remove unused DenseMapInfo::getEmptyKey (PR #201994)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 19:53:17 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/201994

After #201281 DenseMapInfo<T>::getEmptyKey() is no longer used by
DenseMap. Remove the unused getEmptyKey definitions and dead sentinel
uses.


>From c303addd01b05b9d3435704c7ed6c70114ded66b Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 5 Jun 2026 19:08:18 -0700
Subject: [PATCH] [CodeGen][Transforms] Remove unused DenseMapInfo::getEmptyKey

After #201281 DenseMapInfo<T>::getEmptyKey() is no longer used by
DenseMap. Remove the unused getEmptyKey definitions and dead sentinel
uses.
---
 llvm/include/llvm/CodeGen/AccelTable.h        |  3 --
 llvm/include/llvm/CodeGen/MachineBasicBlock.h |  3 --
 llvm/include/llvm/CodeGen/MachineInstr.h      |  6 ---
 llvm/include/llvm/CodeGen/MachineOperand.h    |  4 --
 .../include/llvm/CodeGen/PBQP/CostAllocator.h |  6 ---
 llvm/include/llvm/CodeGen/Register.h          |  3 --
 llvm/include/llvm/CodeGen/SelectionDAGNodes.h |  6 ---
 llvm/include/llvm/CodeGen/TargetInstrInfo.h   |  5 ---
 .../llvm/DebugInfo/CodeView/TypeHashing.h     |  4 --
 .../llvm/DebugInfo/CodeView/TypeIndex.h       |  3 --
 .../DebugInfo/DWARF/DWARFAcceleratorTable.h   |  1 -
 llvm/include/llvm/DebugInfo/GSYM/FileEntry.h  |  4 --
 llvm/include/llvm/Transforms/IPO/Attributor.h | 18 --------
 llvm/include/llvm/Transforms/IPO/IROutliner.h |  7 +--
 .../llvm/Transforms/Scalar/GVNExpression.h    |  4 --
 .../Transforms/Utils/BypassSlowDivision.h     |  4 --
 .../Vectorize/SandboxVectorizer/VecUtils.h    |  3 --
 llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h   |  4 --
 .../CodeGen/AssignmentTrackingAnalysis.cpp    |  3 --
 .../lib/CodeGen/ComplexDeinterleavingPass.cpp |  4 --
 .../LiveDebugValues/InstrRefBasedImpl.h       |  4 --
 llvm/lib/CodeGen/MachineOutliner.cpp          | 13 +-----
 llvm/lib/CodeGen/StackMaps.cpp                |  2 -
 .../DebugInfo/DWARF/DWARFAcceleratorTable.cpp |  4 --
 .../DebugInfo/PDB/Native/GSIStreamBuilder.cpp |  4 --
 llvm/lib/Transforms/IPO/Attributor.cpp        |  2 -
 .../Transforms/IPO/AttributorAttributes.cpp   | 21 ---------
 .../Transforms/IPO/FunctionSpecialization.cpp |  2 -
 .../lib/Transforms/IPO/WholeProgramDevirt.cpp |  8 ----
 .../Transforms/InstCombine/InstCombinePHI.cpp |  3 --
 llvm/lib/Transforms/Scalar/EarlyCSE.cpp       | 43 +++----------------
 llvm/lib/Transforms/Scalar/GVN.cpp            |  2 -
 llvm/lib/Transforms/Scalar/GVNSink.cpp        |  5 ---
 llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp |  4 --
 llvm/lib/Transforms/Scalar/NewGVN.cpp         | 10 -----
 .../Utils/CanonicalizeFreezeInLoops.cpp       |  5 ---
 llvm/lib/Transforms/Utils/Local.cpp           | 17 +-------
 llvm/lib/Transforms/Utils/SimplifyCFG.cpp     |  7 ---
 .../Vectorize/LoadStoreVectorizer.cpp         |  3 --
 .../Transforms/Vectorize/LoopVectorize.cpp    |  6 ---
 .../Transforms/Vectorize/SLPVectorizer.cpp    | 11 -----
 .../Transforms/Vectorize/VPlanTransforms.cpp  |  6 ---
 42 files changed, 8 insertions(+), 269 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/AccelTable.h b/llvm/include/llvm/CodeGen/AccelTable.h
index e2f5b538d415b..a3700e4c2d189 100644
--- a/llvm/include/llvm/CodeGen/AccelTable.h
+++ b/llvm/include/llvm/CodeGen/AccelTable.h
@@ -271,9 +271,6 @@ struct OffsetAndUnitID {
 };
 
 template <> struct DenseMapInfo<OffsetAndUnitID> {
-  static inline OffsetAndUnitID getEmptyKey() {
-    return OffsetAndUnitID(-1, -1, false);
-  }
   static unsigned getHashValue(const OffsetAndUnitID &Val) {
     return (unsigned)llvm::hash_combine(Val.offset(), Val.unitID(), Val.IsTU);
   }
diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index f995b4e4daf47..0aa2bc1bf6cbb 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -85,9 +85,6 @@ template <> struct DenseMapInfo<MBBSectionID> {
   using TypeInfo = DenseMapInfo<MBBSectionID::SectionType>;
   using NumberInfo = DenseMapInfo<unsigned>;
 
-  static inline MBBSectionID getEmptyKey() {
-    return MBBSectionID(NumberInfo::getEmptyKey());
-  }
   static unsigned getHashValue(const MBBSectionID &SecID) {
     return detail::combineHashValue(TypeInfo::getHashValue(SecID.Type),
                                     NumberInfo::getHashValue(SecID.Number));
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index 5f359d840d201..d1c731c2500e4 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -2126,16 +2126,10 @@ class MachineInstr
 /// The hashing and equality testing functions ignore definitions so this is
 /// useful for CSE, etc.
 struct MachineInstrExpressionTrait : DenseMapInfo<MachineInstr*> {
-  static inline MachineInstr *getEmptyKey() {
-    return nullptr;
-  }
-
   LLVM_ABI static unsigned getHashValue(const MachineInstr *const &MI);
 
   static bool isEqual(const MachineInstr* const &LHS,
                       const MachineInstr* const &RHS) {
-    if (RHS == getEmptyKey() || LHS == getEmptyKey())
-      return LHS == RHS;
     return LHS->isIdenticalTo(*RHS, MachineInstr::IgnoreVRegDefs);
   }
 };
diff --git a/llvm/include/llvm/CodeGen/MachineOperand.h b/llvm/include/llvm/CodeGen/MachineOperand.h
index 330df197ef04b..a4734afeddc96 100644
--- a/llvm/include/llvm/CodeGen/MachineOperand.h
+++ b/llvm/include/llvm/CodeGen/MachineOperand.h
@@ -1036,10 +1036,6 @@ class MachineOperand {
 };
 
 template <> struct DenseMapInfo<MachineOperand> {
-  static MachineOperand getEmptyKey() {
-    return MachineOperand(static_cast<MachineOperand::MachineOperandType>(
-        MachineOperand::MO_Empty));
-  }
   static unsigned getHashValue(const MachineOperand &MO) {
     return hash_value(MO);
   }
diff --git a/llvm/include/llvm/CodeGen/PBQP/CostAllocator.h b/llvm/include/llvm/CodeGen/PBQP/CostAllocator.h
index 09f3e35ebc4f7..4f368904b2568 100644
--- a/llvm/include/llvm/CodeGen/PBQP/CostAllocator.h
+++ b/llvm/include/llvm/CodeGen/PBQP/CostAllocator.h
@@ -47,8 +47,6 @@ template <typename ValueT> class ValuePool {
 
   class PoolEntryDSInfo {
   public:
-    static inline PoolEntry *getEmptyKey() { return nullptr; }
-
     template <typename ValueKeyT>
     static unsigned getHashValue(const ValueKeyT &C) {
       return hash_value(C);
@@ -69,14 +67,10 @@ template <typename ValueT> class ValuePool {
 
     template <typename ValueKeyT>
     static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
-      if (P == getEmptyKey())
-        return false;
       return isEqual(C, P->getValue());
     }
 
     static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
-      if (P1 == getEmptyKey())
-        return P1 == P2;
       return isEqual(P1->getValue(), P2);
     }
   };
diff --git a/llvm/include/llvm/CodeGen/Register.h b/llvm/include/llvm/CodeGen/Register.h
index 28e7498f0c05f..3682f5166dd7d 100644
--- a/llvm/include/llvm/CodeGen/Register.h
+++ b/llvm/include/llvm/CodeGen/Register.h
@@ -163,9 +163,6 @@ class Register {
 
 // Provide DenseMapInfo for Register
 template <> struct DenseMapInfo<Register> {
-  static inline Register getEmptyKey() {
-    return DenseMapInfo<unsigned>::getEmptyKey();
-  }
   static unsigned getHashValue(const Register &Val) {
     return DenseMapInfo<unsigned>::getHashValue(Val.id());
   }
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index cc7225c3c82cf..2906dfe03d346 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -239,12 +239,6 @@ class SDValue {
 };
 
 template<> struct DenseMapInfo<SDValue> {
-  static inline SDValue getEmptyKey() {
-    SDValue V;
-    V.ResNo = -1U;
-    return V;
-  }
-
   static unsigned getHashValue(const SDValue &Val) {
     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
index dbe87b8ae0cd5..03f3bf26d0608 100644
--- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -2417,11 +2417,6 @@ template <> struct DenseMapInfo<TargetInstrInfo::RegSubRegPair> {
   using RegInfo = DenseMapInfo<Register>;
   using SubRegInfo = DenseMapInfo<unsigned>;
 
-  static inline TargetInstrInfo::RegSubRegPair getEmptyKey() {
-    return TargetInstrInfo::RegSubRegPair(RegInfo::getEmptyKey(),
-                                          SubRegInfo::getEmptyKey());
-  }
-
   /// Reuse getHashValue implementation from
   /// std::pair<unsigned, unsigned>.
   static unsigned getHashValue(const TargetInstrInfo::RegSubRegPair &Val) {
diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h b/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
index 6a5ab81dfabc1..0f3b551134fd9 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeHashing.h
@@ -185,8 +185,6 @@ static_assert(std::is_trivially_copyable<GloballyHashedType>::value,
 template <> struct DenseMapInfo<codeview::LocallyHashedType> {
   LLVM_ABI static codeview::LocallyHashedType Empty;
 
-  static codeview::LocallyHashedType getEmptyKey() { return Empty; }
-
   static unsigned getHashValue(codeview::LocallyHashedType Val) {
     return Val.Hash;
   }
@@ -202,8 +200,6 @@ template <> struct DenseMapInfo<codeview::LocallyHashedType> {
 template <> struct DenseMapInfo<codeview::GloballyHashedType> {
   LLVM_ABI static codeview::GloballyHashedType Empty;
 
-  static codeview::GloballyHashedType getEmptyKey() { return Empty; }
-
   static unsigned getHashValue(codeview::GloballyHashedType Val) {
     return *reinterpret_cast<const unsigned *>(Val.Hash.data());
   }
diff --git a/llvm/include/llvm/DebugInfo/CodeView/TypeIndex.h b/llvm/include/llvm/DebugInfo/CodeView/TypeIndex.h
index d9c506fa215ad..e799f58f91141 100644
--- a/llvm/include/llvm/DebugInfo/CodeView/TypeIndex.h
+++ b/llvm/include/llvm/DebugInfo/CodeView/TypeIndex.h
@@ -290,9 +290,6 @@ LLVM_ABI void printTypeIndex(ScopedPrinter &Printer, StringRef FieldName,
 }
 
 template <> struct DenseMapInfo<codeview::TypeIndex> {
-  static inline codeview::TypeIndex getEmptyKey() {
-    return codeview::TypeIndex{DenseMapInfo<uint32_t>::getEmptyKey()};
-  }
   static unsigned getHashValue(const codeview::TypeIndex &TI) {
     return DenseMapInfo<uint32_t>::getHashValue(TI.getIndex());
   }
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
index 8f8ffa55e4d34..832e8c32db4a9 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h
@@ -535,7 +535,6 @@ class LLVM_ABI DWARFDebugNames : public DWARFAcceleratorTable {
 private:
   /// DenseMapInfo for struct Abbrev.
   struct AbbrevMapInfo {
-    LLVM_ABI static Abbrev getEmptyKey();
     static unsigned getHashValue(uint32_t Code) {
       return DenseMapInfo<uint32_t>::getHashValue(Code);
     }
diff --git a/llvm/include/llvm/DebugInfo/GSYM/FileEntry.h b/llvm/include/llvm/DebugInfo/GSYM/FileEntry.h
index a4f935cd557b8..7276fa91438de 100644
--- a/llvm/include/llvm/DebugInfo/GSYM/FileEntry.h
+++ b/llvm/include/llvm/DebugInfo/GSYM/FileEntry.h
@@ -52,10 +52,6 @@ struct FileEntry {
 } // namespace gsym
 
 template <> struct DenseMapInfo<gsym::FileEntry> {
-  static inline gsym::FileEntry getEmptyKey() {
-    gsym::gsym_strp_t key = DenseMapInfo<gsym::gsym_strp_t>::getEmptyKey();
-    return gsym::FileEntry(key, key);
-  }
   static unsigned getHashValue(const gsym::FileEntry &Val) {
     return llvm::hash_combine(
         DenseMapInfo<gsym::gsym_strp_t>::getHashValue(Val.Dir),
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 79490a1c90985..c0658c10f9d23 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -431,9 +431,6 @@ template <>
 struct DenseMapInfo<AA::ValueAndContext>
     : public DenseMapInfo<AA::ValueAndContext::Base> {
   using Base = DenseMapInfo<AA::ValueAndContext::Base>;
-  static inline AA::ValueAndContext getEmptyKey() {
-    return Base::getEmptyKey();
-  }
   static unsigned getHashValue(const AA::ValueAndContext &VAC) {
     return Base::getHashValue(VAC);
   }
@@ -447,9 +444,6 @@ struct DenseMapInfo<AA::ValueAndContext>
 template <>
 struct DenseMapInfo<AA::ValueScope> : public DenseMapInfo<unsigned char> {
   using Base = DenseMapInfo<unsigned char>;
-  static inline AA::ValueScope getEmptyKey() {
-    return AA::ValueScope(Base::getEmptyKey());
-  }
   static unsigned getHashValue(const AA::ValueScope &S) {
     return Base::getHashValue(S);
   }
@@ -463,9 +457,6 @@ template <>
 struct DenseMapInfo<const AA::InstExclusionSetTy *>
     : public DenseMapInfo<void *> {
   using super = DenseMapInfo<void *>;
-  static inline const AA::InstExclusionSetTy *getEmptyKey() {
-    return static_cast<const AA::InstExclusionSetTy *>(super::getEmptyKey());
-  }
   static unsigned getHashValue(const AA::InstExclusionSetTy *BES) {
     unsigned H = 0;
     if (BES)
@@ -477,8 +468,6 @@ struct DenseMapInfo<const AA::InstExclusionSetTy *>
                       const AA::InstExclusionSetTy *RHS) {
     if (LHS == RHS)
       return true;
-    if (LHS == getEmptyKey() || RHS == getEmptyKey())
-      return false;
     auto SizeLHS = LHS ? LHS->size() : 0;
     auto SizeRHS = RHS ? RHS->size() : 0;
     if (SizeLHS != SizeRHS)
@@ -942,12 +931,6 @@ struct IRPosition {
   /// Check if the position has any call base context.
   bool hasCallBaseContext() const { return CBContext != nullptr; }
 
-  /// Special DenseMap key values.
-  ///
-  ///{
-  LLVM_ABI static const IRPosition EmptyKey;
-  ///}
-
   /// Conversion into a void * to allow reuse of pointer hashing.
   operator void *() const { return Enc.getOpaqueValue(); }
 
@@ -1082,7 +1065,6 @@ struct IRPosition {
 
 /// Helper that allows IRPosition as a key in a DenseMap.
 template <> struct DenseMapInfo<IRPosition> {
-  static inline IRPosition getEmptyKey() { return IRPosition::EmptyKey; }
   static unsigned getHashValue(const IRPosition &IRP) {
     return (DenseMapInfo<void *>::getHashValue(IRP) << 4) ^
            (DenseMapInfo<Value *>::getHashValue(IRP.getCallBaseContext()));
diff --git a/llvm/include/llvm/Transforms/IPO/IROutliner.h b/llvm/include/llvm/Transforms/IPO/IROutliner.h
index e2e422f7560c3..e7cc728124a9a 100644
--- a/llvm/include/llvm/Transforms/IPO/IROutliner.h
+++ b/llvm/include/llvm/Transforms/IPO/IROutliner.h
@@ -202,12 +202,7 @@ class IROutliner {
   IROutliner(function_ref<TargetTransformInfo &(Function &)> GTTI,
              function_ref<IRSimilarityIdentifier &(Module &)> GIRSI,
              function_ref<OptimizationRemarkEmitter &(Function &)> GORE)
-      : getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {
-    
-    // Check that the DenseMap implementation has not changed.
-    static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
-                  static_cast<unsigned>(-1));
-  }
+      : getTTI(GTTI), getIRSI(GIRSI), getORE(GORE) {}
   LLVM_ABI bool run(Module &M);
 
 private:
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
index 107a133209e9d..a702e66828649 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
@@ -70,14 +70,10 @@ class LLVM_ABI Expression {
   Expression &operator=(const Expression &) = delete;
   virtual ~Expression();
 
-  static unsigned getEmptyKey() { return ~0U; }
-
   bool operator!=(const Expression &Other) const { return !(*this == Other); }
   bool operator==(const Expression &Other) const {
     if (getOpcode() != Other.getOpcode())
       return false;
-    if (getOpcode() == getEmptyKey())
-      return true;
     // Compare the expression type for anything but load and store.
     // For load and store we set the opcode to zero to make them equal.
     if (getExpressionType() != ET_Load && getExpressionType() != ET_Store &&
diff --git a/llvm/include/llvm/Transforms/Utils/BypassSlowDivision.h b/llvm/include/llvm/Transforms/Utils/BypassSlowDivision.h
index d5a31370ff0f9..981702e6c6ebb 100644
--- a/llvm/include/llvm/Transforms/Utils/BypassSlowDivision.h
+++ b/llvm/include/llvm/Transforms/Utils/BypassSlowDivision.h
@@ -46,10 +46,6 @@ template <> struct DenseMapInfo<DivRemMapKey> {
            Val1.Divisor == Val2.Divisor;
   }
 
-  static DivRemMapKey getEmptyKey() {
-    return DivRemMapKey(false, nullptr, nullptr);
-  }
-
   static unsigned getHashValue(const DivRemMapKey &Val) {
     return (unsigned)(reinterpret_cast<uintptr_t>(
                           static_cast<Value *>(Val.Dividend)) ^
diff --git a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
index 11d4afe5cf271..99e411a1723b0 100644
--- a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
+++ b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/VecUtils.h
@@ -22,9 +22,6 @@
 namespace llvm {
 /// Traits for DenseMap.
 template <> struct DenseMapInfo<SmallVector<sandboxir::Value *>> {
-  static inline SmallVector<sandboxir::Value *> getEmptyKey() {
-    return SmallVector<sandboxir::Value *>({(sandboxir::Value *)-1});
-  }
   static unsigned getHashValue(const SmallVector<sandboxir::Value *> &Vec) {
     return hash_combine_range(Vec);
   }
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
index c25323b1ee00c..04a75a21d7679 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
@@ -548,10 +548,6 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
 
 template <> struct DenseMapInfo<CodeViewDebug::LocalVarDef> {
 
-  static inline CodeViewDebug::LocalVarDef getEmptyKey() {
-    return CodeViewDebug::LocalVarDef::emptyValue();
-  }
-
   static unsigned getHashValue(const CodeViewDebug::LocalVarDef &DR) {
     return DR.hashValue();
   }
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index 518639e2854eb..4aebb4b9f37f6 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -70,9 +70,6 @@ static cl::opt<cl::boolOrDefault>
 // need to create a DenseMapInfo wrapper around the specified underlying type.
 template <> struct llvm::DenseMapInfo<VariableID> {
   using Wrapped = DenseMapInfo<unsigned>;
-  static inline VariableID getEmptyKey() {
-    return static_cast<VariableID>(Wrapped::getEmptyKey());
-  }
   static unsigned getHashValue(const VariableID &Val) {
     return Wrapped::getHashValue(static_cast<unsigned>(Val));
   }
diff --git a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
index 90b06cb9f902a..60eb96fc5de1b 100644
--- a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
+++ b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
@@ -127,10 +127,6 @@ hash_code hash_value(const ComplexValue &Arg) {
 typedef SmallVector<struct ComplexValue, 2> ComplexValues;
 
 template <> struct llvm::DenseMapInfo<ComplexValue> {
-  static inline ComplexValue getEmptyKey() {
-    return {DenseMapInfo<Value *>::getEmptyKey(),
-            DenseMapInfo<Value *>::getEmptyKey()};
-  }
   static unsigned getHashValue(const ComplexValue &Val) {
     return hash_combine(DenseMapInfo<Value *>::getHashValue(Val.Real),
                         DenseMapInfo<Value *>::getHashValue(Val.Imag));
diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
index 6426124b59c46..184f07cb9fdf8 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
+++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
@@ -209,16 +209,12 @@ namespace llvm {
 using namespace LiveDebugValues;
 
 template <> struct DenseMapInfo<LocIdx> {
-  static inline LocIdx getEmptyKey() { return LocIdx::MakeIllegalLoc(); }
-
   static unsigned getHashValue(const LocIdx &Loc) { return Loc.asU64(); }
 
   static bool isEqual(const LocIdx &A, const LocIdx &B) { return A == B; }
 };
 
 template <> struct DenseMapInfo<ValueIDNum> {
-  static inline ValueIDNum getEmptyKey() { return ValueIDNum::EmptyValue; }
-
   static unsigned getHashValue(const ValueIDNum &Val) {
     return hash_value(Val.asU64());
   }
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index e1ff8891f2fe2..9c92c7bf2369b 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -244,9 +244,6 @@ struct InstructionMapper {
     if (LegalInstrNumber >= IllegalInstrNumber)
       report_fatal_error("Instruction mapping overflow!");
 
-    assert(LegalInstrNumber != DenseMapInfo<unsigned>::getEmptyKey() &&
-           "Tried to assign DenseMap empty key to instruction.");
-
     // Statistics.
     ++NumLegalInUnsignedVec;
     return MINumber;
@@ -282,9 +279,6 @@ struct InstructionMapper {
     assert(LegalInstrNumber < IllegalInstrNumber &&
            "Instruction mapping overflow!");
 
-    assert(IllegalInstrNumber != DenseMapInfo<unsigned>::getEmptyKey() &&
-           "IllegalInstrNumber cannot be DenseMap empty key!");
-
     return MINumber;
   }
 
@@ -413,12 +407,7 @@ struct InstructionMapper {
     }
   }
 
-  InstructionMapper(const MachineModuleInfo &MMI_) : MMI(MMI_) {
-    // Make sure that the implementation of DenseMapInfo<unsigned> hasn't
-    // changed.
-    static_assert(DenseMapInfo<unsigned>::getEmptyKey() ==
-                  static_cast<unsigned>(-1));
-  }
+  InstructionMapper(const MachineModuleInfo &MMI_) : MMI(MMI_) {}
 };
 
 /// An interprocedural pass which finds repeated sequences of
diff --git a/llvm/lib/CodeGen/StackMaps.cpp b/llvm/lib/CodeGen/StackMaps.cpp
index f53136809513b..4e95f883ce31b 100644
--- a/llvm/lib/CodeGen/StackMaps.cpp
+++ b/llvm/lib/CodeGen/StackMaps.cpp
@@ -245,8 +245,6 @@ StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
         // where we have to insert the empty key into a map, and for a
         // DenseMap<uint64_t, T> this is (uint64_t)-1.  It can be and is
         // represented using 32 bit integers.
-        assert((uint64_t)Imm != DenseMapInfo<uint64_t>::getEmptyKey() &&
-               "empty key should fit in 32 bits!");
         auto Result = ConstPool.insert(std::make_pair(Imm, Imm));
         Locs.emplace_back(Location::ConstantIndex, sizeof(int64_t), 0,
                           Result.first - ConstPool.begin());
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
index 7787261bc2162..2a6014194316d 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
@@ -512,10 +512,6 @@ static bool isSentinel(const DWARFDebugNames::Abbrev &Abbr) {
   return Abbr.Code == 0;
 }
 
-DWARFDebugNames::Abbrev DWARFDebugNames::AbbrevMapInfo::getEmptyKey() {
-  return sentinelAbbrev();
-}
-
 Expected<DWARFDebugNames::AttributeEncoding>
 DWARFDebugNames::NameIndex::extractAttributeEncoding(uint64_t *Offset) {
   if (*Offset >= Offsets.EntriesBase) {
diff --git a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
index a64a341de4acd..f60d708bbbe8e 100644
--- a/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
@@ -68,10 +68,6 @@ struct llvm::pdb::GSIHashStreamBuilder {
 
 // DenseMapInfo implementation for deduplicating symbol records.
 struct llvm::pdb::SymbolDenseMapInfo {
-  static inline CVSymbol getEmptyKey() {
-    static CVSymbol Empty;
-    return Empty;
-  }
   static unsigned getHashValue(const CVSymbol &Val) {
     return xxh3_64bits(Val.RecordData);
   }
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 2342d90e82b37..0c4cc5451e736 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1332,8 +1332,6 @@ ChangeStatus Attributor::manifestAttrs(const IRPosition &IRP,
   return updateAttrMap<Attribute>(IRP, Attrs, AddAttrCB);
 }
 
-const IRPosition IRPosition::EmptyKey(DenseMapInfo<void *>::getEmptyKey());
-
 SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) {
   IRPositions.emplace_back(IRP);
 
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 6941d46b15d37..fff97ff3efe5b 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -745,18 +745,12 @@ struct State;
 template <>
 struct DenseMapInfo<AAPointerInfo::Access> : DenseMapInfo<Instruction *> {
   using Access = AAPointerInfo::Access;
-  static inline Access getEmptyKey();
   static unsigned getHashValue(const Access &A);
   static bool isEqual(const Access &LHS, const Access &RHS);
 };
 
 /// Helper that allows RangeTy as a key in a DenseMap.
 template <> struct DenseMapInfo<AA::RangeTy> {
-  static inline AA::RangeTy getEmptyKey() {
-    auto EmptyKey = DenseMapInfo<int64_t>::getEmptyKey();
-    return AA::RangeTy{EmptyKey, EmptyKey};
-  }
-
   static unsigned getHashValue(const AA::RangeTy &Range) {
     return detail::combineHashValue(
         DenseMapInfo<int64_t>::getHashValue(Range.Offset),
@@ -773,7 +767,6 @@ template <> struct DenseMapInfo<AA::RangeTy> {
 struct AccessAsInstructionInfo : DenseMapInfo<Instruction *> {
   using Base = DenseMapInfo<Instruction *>;
   using Access = AAPointerInfo::Access;
-  static inline Access getEmptyKey();
   static unsigned getHashValue(const Access &A);
   static bool isEqual(const Access &LHS, const Access &RHS);
 };
@@ -3469,9 +3462,6 @@ template <typename ToTy> struct DenseMapInfo<ReachabilityQueryInfo<ToTy> *> {
   using InstSetDMI = DenseMapInfo<const AA::InstExclusionSetTy *>;
   using PairDMI = DenseMapInfo<std::pair<const Instruction *, const ToTy *>>;
 
-  static ReachabilityQueryInfo<ToTy> EmptyKey;
-
-  static inline ReachabilityQueryInfo<ToTy> *getEmptyKey() { return &EmptyKey; }
   static unsigned getHashValue(const ReachabilityQueryInfo<ToTy> *RQI) {
     return RQI->Hash ? RQI->Hash : RQI->computeHashValue();
   }
@@ -3483,17 +3473,6 @@ template <typename ToTy> struct DenseMapInfo<ReachabilityQueryInfo<ToTy> *> {
   }
 };
 
-#define DefineKeys(ToTy)                                                       \
-  template <>                                                                  \
-  ReachabilityQueryInfo<ToTy>                                                  \
-      DenseMapInfo<ReachabilityQueryInfo<ToTy> *>::EmptyKey =                  \
-          ReachabilityQueryInfo<ToTy>(                                         \
-              DenseMapInfo<const Instruction *>::getEmptyKey(),                \
-              DenseMapInfo<const ToTy *>::getEmptyKey());
-
-DefineKeys(Instruction) DefineKeys(Function)
-#undef DefineKeys
-
 } // namespace llvm
 
 namespace {
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 5cf8cb989f4a4..fb741f35cbd6d 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -633,8 +633,6 @@ void FunctionSpecializer::cleanUpSSA() {
 }
 
 template <> struct llvm::DenseMapInfo<SpecSig> {
-  static inline SpecSig getEmptyKey() { return {~0U, {}}; }
-
   static unsigned getHashValue(const SpecSig &S) {
     return static_cast<unsigned>(hash_value(S));
   }
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 8d477b7bdeeba..3a03043e32c49 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -383,10 +383,6 @@ struct VTableSlot {
 } // end anonymous namespace
 
 template <> struct llvm::DenseMapInfo<VTableSlot> {
-  static VTableSlot getEmptyKey() {
-    return {DenseMapInfo<Metadata *>::getEmptyKey(),
-            DenseMapInfo<uint64_t>::getEmptyKey()};
-  }
   static unsigned getHashValue(const VTableSlot &I) {
     return DenseMapInfo<Metadata *>::getHashValue(I.TypeID) ^
            DenseMapInfo<uint64_t>::getHashValue(I.ByteOffset);
@@ -398,10 +394,6 @@ template <> struct llvm::DenseMapInfo<VTableSlot> {
 };
 
 template <> struct llvm::DenseMapInfo<VTableSlotSummary> {
-  static VTableSlotSummary getEmptyKey() {
-    return {DenseMapInfo<StringRef>::getEmptyKey(),
-            DenseMapInfo<uint64_t>::getEmptyKey()};
-  }
   static unsigned getHashValue(const VTableSlotSummary &I) {
     return DenseMapInfo<StringRef>::getHashValue(I.TypeID) ^
            DenseMapInfo<uint64_t>::getHashValue(I.ByteOffset);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 4dc93244adeec..ce3175c4936de 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -1048,9 +1048,6 @@ struct LoweredPHIRecord {
 } // namespace
 
 template <> struct llvm::DenseMapInfo<LoweredPHIRecord> {
-  static inline LoweredPHIRecord getEmptyKey() {
-    return LoweredPHIRecord(nullptr, 0);
-  }
   static unsigned getHashValue(const LoweredPHIRecord &Val) {
     return DenseMapInfo<PHINode *>::getHashValue(Val.PN) ^ (Val.Shift >> 3) ^
            (Val.Width >> 3);
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 242340a8fade9..3dd84bddb6bf5 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -94,11 +94,7 @@ struct SimpleValue {
   Instruction *Inst;
 
   SimpleValue(Instruction *I) : Inst(I) {
-    assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
-  }
-
-  bool isSentinel() const {
-    return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
+    assert(canHandle(I) && "Inst can't be handled!");
   }
 
   static bool canHandle(Instruction *Inst) {
@@ -154,10 +150,6 @@ struct SimpleValue {
 } // end anonymous namespace
 
 template <> struct llvm::DenseMapInfo<SimpleValue> {
-  static inline SimpleValue getEmptyKey() {
-    return DenseMapInfo<Instruction *>::getEmptyKey();
-  }
-
   static unsigned getHashValue(SimpleValue Val);
   static bool isEqual(SimpleValue LHS, SimpleValue RHS);
 };
@@ -345,9 +337,6 @@ unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
 static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS) {
   Instruction *LHSI = LHS.Inst, *RHSI = RHS.Inst;
 
-  if (LHS.isSentinel() || RHS.isSentinel())
-    return LHSI == RHSI;
-
   if (LHSI->getOpcode() != RHSI->getOpcode())
     return false;
   if (LHSI->isIdenticalToWhenDefined(RHSI, /*IntersectAttrs=*/true)) {
@@ -457,8 +446,7 @@ bool DenseMapInfo<SimpleValue>::isEqual(SimpleValue LHS, SimpleValue RHS) {
   // These comparisons are nontrivial, so assert that equality implies
   // hash equality (DenseMap demands this as an invariant).
   bool Result = isEqualImpl(LHS, RHS);
-  assert(!Result || (LHS.isSentinel() && LHS.Inst == RHS.Inst) ||
-         getHashValueImpl(LHS) == getHashValueImpl(RHS));
+  assert(!Result || getHashValueImpl(LHS) == getHashValueImpl(RHS));
   return Result;
 }
 
@@ -474,11 +462,7 @@ struct CallValue {
   Instruction *Inst;
 
   CallValue(Instruction *I) : Inst(I) {
-    assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
-  }
-
-  bool isSentinel() const {
-    return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
+    assert(canHandle(I) && "Inst can't be handled!");
   }
 
   static bool canHandle(Instruction *Inst) {
@@ -500,10 +484,6 @@ struct CallValue {
 } // end anonymous namespace
 
 template <> struct llvm::DenseMapInfo<CallValue> {
-  static inline CallValue getEmptyKey() {
-    return DenseMapInfo<Instruction *>::getEmptyKey();
-  }
-
   static unsigned getHashValue(CallValue Val);
   static bool isEqual(CallValue LHS, CallValue RHS);
 };
@@ -516,9 +496,6 @@ unsigned DenseMapInfo<CallValue>::getHashValue(CallValue Val) {
 }
 
 bool DenseMapInfo<CallValue>::isEqual(CallValue LHS, CallValue RHS) {
-  if (LHS.isSentinel() || RHS.isSentinel())
-    return LHS.Inst == RHS.Inst;
-
   CallInst *LHSI = cast<CallInst>(LHS.Inst);
   CallInst *RHSI = cast<CallInst>(RHS.Inst);
 
@@ -542,16 +519,12 @@ struct GEPValue {
   std::optional<int64_t> ConstantOffset;
 
   GEPValue(Instruction *I) : Inst(I) {
-    assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
+    assert(canHandle(I) && "Inst can't be handled!");
   }
 
   GEPValue(Instruction *I, std::optional<int64_t> ConstantOffset)
       : Inst(I), ConstantOffset(ConstantOffset) {
-    assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
-  }
-
-  bool isSentinel() const {
-    return Inst == DenseMapInfo<Instruction *>::getEmptyKey();
+    assert(canHandle(I) && "Inst can't be handled!");
   }
 
   static bool canHandle(Instruction *Inst) {
@@ -562,10 +535,6 @@ struct GEPValue {
 } // namespace
 
 template <> struct llvm::DenseMapInfo<GEPValue> {
-  static inline GEPValue getEmptyKey() {
-    return DenseMapInfo<Instruction *>::getEmptyKey();
-  }
-
   static unsigned getHashValue(const GEPValue &Val);
   static bool isEqual(const GEPValue &LHS, const GEPValue &RHS);
 };
@@ -580,8 +549,6 @@ unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
 }
 
 bool DenseMapInfo<GEPValue>::isEqual(const GEPValue &LHS, const GEPValue &RHS) {
-  if (LHS.isSentinel() || RHS.isSentinel())
-    return LHS.Inst == RHS.Inst;
   auto *LGEP = cast<GetElementPtrInst>(LHS.Inst);
   auto *RGEP = cast<GetElementPtrInst>(RHS.Inst);
   if (LGEP->getPointerOperand() != RGEP->getPointerOperand())
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index db018a313f110..a0cf879c4eee5 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -177,8 +177,6 @@ struct llvm::GVNPass::Expression {
 };
 
 template <> struct llvm::DenseMapInfo<GVNPass::Expression> {
-  static inline GVNPass::Expression getEmptyKey() { return ~0U; }
-
   static unsigned getHashValue(const GVNPass::Expression &E) {
     using llvm::hash_value;
 
diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp
index decb29e8ba7d4..95e0f7d9a6b60 100644
--- a/llvm/lib/Transforms/Scalar/GVNSink.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp
@@ -255,11 +255,6 @@ static raw_ostream &operator<<(raw_ostream &OS,
 #endif
 
 template <> struct llvm::DenseMapInfo<ModelledPHI> {
-  static inline ModelledPHI &getEmptyKey() {
-    static ModelledPHI Dummy = ModelledPHI::createDummy(0);
-    return Dummy;
-  }
-
   static unsigned getHashValue(const ModelledPHI &V) { return V.hash(); }
 
   static bool isEqual(const ModelledPHI &LHS, const ModelledPHI &RHS) {
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 00cf6b3e7988b..7034e595a4435 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -303,10 +303,6 @@ struct UnrolledInstStateKeyInfo {
   using PtrInfo = DenseMapInfo<Instruction *>;
   using PairInfo = DenseMapInfo<std::pair<Instruction *, int>>;
 
-  static inline UnrolledInstState getEmptyKey() {
-    return {PtrInfo::getEmptyKey(), 0, 0, 0};
-  }
-
   static inline unsigned getHashValue(const UnrolledInstState &S) {
     return PairInfo::getHashValue({S.I, S.Iteration});
   }
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index d797994e83374..1adbfb9c2c7d6 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -442,12 +442,6 @@ struct ExactEqualsExpression {
 } // end anonymous namespace
 
 template <> struct llvm::DenseMapInfo<const Expression *> {
-  static const Expression *getEmptyKey() {
-    auto Val = static_cast<uintptr_t>(-1);
-    Val <<= PointerLikeTypeTraits<const Expression *>::NumLowBitsAvailable;
-    return reinterpret_cast<const Expression *>(Val);
-  }
-
   static unsigned getHashValue(const Expression *E) {
     return E->getComputedHash();
   }
@@ -457,16 +451,12 @@ template <> struct llvm::DenseMapInfo<const Expression *> {
   }
 
   static bool isEqual(const ExactEqualsExpression &LHS, const Expression *RHS) {
-    if (RHS == getEmptyKey())
-      return false;
     return LHS == *RHS;
   }
 
   static bool isEqual(const Expression *LHS, const Expression *RHS) {
     if (LHS == RHS)
       return true;
-    if (LHS == getEmptyKey() || RHS == getEmptyKey())
-      return false;
     // Compare hashes before equality.  This is *not* what the hashtable does,
     // since it is computing it modulo the number of buckets, whereas we are
     // using the full hash keyspace.  Since the hashes are precomputed, this
diff --git a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
index af904fb497cbf..912f4d90551ce 100644
--- a/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
+++ b/llvm/lib/Transforms/Utils/CanonicalizeFreezeInLoops.cpp
@@ -102,11 +102,6 @@ struct FrozenIndPHIInfo {
 } // namespace
 
 template <> struct llvm::DenseMapInfo<FrozenIndPHIInfo> {
-  static inline FrozenIndPHIInfo getEmptyKey() {
-    return FrozenIndPHIInfo(DenseMapInfo<PHINode *>::getEmptyKey(),
-                            DenseMapInfo<BinaryOperator *>::getEmptyKey());
-  }
-
   static unsigned getHashValue(const FrozenIndPHIInfo &Val) {
     return DenseMapInfo<FreezeInst *>::getHashValue(Val.FI);
   };
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 8fa62b34c2b0a..1e1c3ac56d9c1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1432,12 +1432,6 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
   // one having an undef where the other doesn't could be collapsed.
 
   struct PHIDenseMapInfo {
-    static PHINode *getEmptyKey() {
-      return DenseMapInfo<PHINode *>::getEmptyKey();
-    }
-
-    static bool isSentinel(PHINode *PN) { return PN == getEmptyKey(); }
-
     // WARNING: this logic must be kept in sync with
     //          Instruction::isIdenticalToWhenDefined()!
     static unsigned getHashValueImpl(PHINode *PN) {
@@ -1462,8 +1456,6 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
     }
 
     static bool isEqualImpl(PHINode *LHS, PHINode *RHS) {
-      if (isSentinel(LHS) || isSentinel(RHS))
-        return LHS == RHS;
       return LHS->isIdenticalTo(RHS);
     }
 
@@ -1471,8 +1463,7 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
       // These comparisons are nontrivial, so assert that equality implies
       // hash equality (DenseMap demands this as an invariant).
       bool Result = isEqualImpl(LHS, RHS);
-      assert(!Result || (isSentinel(LHS) && LHS == RHS) ||
-             getHashValueImpl(LHS) == getHashValueImpl(RHS));
+      assert(!Result || getHashValueImpl(LHS) == getHashValueImpl(RHS));
       return Result;
     }
   };
@@ -2817,18 +2808,12 @@ static bool markAliveBlocks(Function &F, SmallVectorImpl<bool> &Reachable,
     } else if (auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
       // Remove catchpads which cannot be reached.
       struct CatchPadDenseMapInfo {
-        static CatchPadInst *getEmptyKey() {
-          return DenseMapInfo<CatchPadInst *>::getEmptyKey();
-        }
-
         static unsigned getHashValue(CatchPadInst *CatchPad) {
           return static_cast<unsigned>(hash_combine_range(
               CatchPad->value_op_begin(), CatchPad->value_op_end()));
         }
 
         static bool isEqual(CatchPadInst *LHS, CatchPadInst *RHS) {
-          if (LHS == getEmptyKey() || RHS == getEmptyKey())
-            return LHS == RHS;
           return LHS->isIdenticalTo(RHS);
         }
       };
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 3503b3f0bd056..8199590292364 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -8056,9 +8056,6 @@ struct EqualBBWrapper {
 };
 
 template <> struct llvm::DenseMapInfo<const EqualBBWrapper *> {
-  static const EqualBBWrapper *getEmptyKey() {
-    return static_cast<EqualBBWrapper *>(DenseMapInfo<void *>::getEmptyKey());
-  }
   static unsigned getHashValue(const EqualBBWrapper *EBW) {
     BasicBlock *BB = EBW->BB;
     UncondBrInst *BI = cast<UncondBrInst>(BB->getTerminator());
@@ -8078,10 +8075,6 @@ template <> struct llvm::DenseMapInfo<const EqualBBWrapper *> {
     return hash_combine(Succ, hash_combine_range(PhiValsForBB));
   }
   static bool isEqual(const EqualBBWrapper *LHS, const EqualBBWrapper *RHS) {
-    auto *EKey = DenseMapInfo<EqualBBWrapper *>::getEmptyKey();
-    if (LHS == EKey || RHS == EKey)
-      return LHS == RHS;
-
     BasicBlock *A = LHS->BB;
     BasicBlock *B = RHS->BB;
 
diff --git a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
index 3f67e7ba9872b..04ccb623d8d72 100644
--- a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -1819,13 +1819,10 @@ std::vector<Chain> Vectorizer::gatherChains(ArrayRef<Instruction *> Instrs) {
   struct InstrListElemDenseMapInfo {
     using PtrInfo = DenseMapInfo<InstrListElem *>;
     using IInfo = DenseMapInfo<Instruction *>;
-    static InstrListElem *getEmptyKey() { return PtrInfo::getEmptyKey(); }
     static unsigned getHashValue(const InstrListElem *E) {
       return IInfo::getHashValue(E->first);
     }
     static bool isEqual(const InstrListElem *A, const InstrListElem *B) {
-      if (A == getEmptyKey() || B == getEmptyKey())
-        return A == getEmptyKey() && B == getEmptyKey();
       return IInfo::isEqual(A->first, B->first);
     }
   };
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index ab0ab803d6bc5..7ad454d4a1797 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2050,10 +2050,6 @@ struct CSEDenseMapInfo {
            isa<ShuffleVectorInst>(I) || isa<GetElementPtrInst>(I);
   }
 
-  static inline Instruction *getEmptyKey() {
-    return DenseMapInfo<Instruction *>::getEmptyKey();
-  }
-
   static unsigned getHashValue(const Instruction *I) {
     assert(canHandle(I) && "Unknown instruction!");
     return hash_combine(I->getOpcode(),
@@ -2061,8 +2057,6 @@ struct CSEDenseMapInfo {
   }
 
   static bool isEqual(const Instruction *LHS, const Instruction *RHS) {
-    if (LHS == getEmptyKey() || RHS == getEmptyKey())
-      return LHS == RHS;
     return LHS->isIdenticalTo(RHS);
   }
 };
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index c0b7fcb2b5864..bc0f1f754c42d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6463,12 +6463,6 @@ class slpvectorizer::BoUpSLP {
   /// A DenseMapInfo implementation for holding DenseMaps and DenseSets of
   /// sorted SmallVectors of unsigned.
   struct OrdersTypeDenseMapInfo {
-    static OrdersType getEmptyKey() {
-      OrdersType V;
-      V.push_back(~1U);
-      return V;
-    }
-
     static unsigned getHashValue(const OrdersType &V) {
       return static_cast<unsigned>(hash_combine_range(V));
     }
@@ -6523,11 +6517,6 @@ class slpvectorizer::BoUpSLP {
 template <> struct llvm::DenseMapInfo<BoUpSLP::EdgeInfo> {
   using FirstInfo = DenseMapInfo<BoUpSLP::TreeEntry *>;
   using SecondInfo = DenseMapInfo<unsigned>;
-  static BoUpSLP::EdgeInfo getEmptyKey() {
-    return BoUpSLP::EdgeInfo(FirstInfo::getEmptyKey(),
-                             SecondInfo::getEmptyKey());
-  }
-
   static unsigned getHashValue(const BoUpSLP::EdgeInfo &Val) {
     return detail::combineHashValue(FirstInfo::getHashValue(Val.UserTE),
                                     SecondInfo::getHashValue(Val.EdgeIdx));
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index e0d06366592ae..46a335277dfd8 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -2409,10 +2409,6 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
 
 namespace {
 struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
-  static bool isSentinel(const VPSingleDefRecipe *Def) {
-    return Def == getEmptyKey();
-  }
-
   /// If recipe \p R will lower to a GEP with a non-i8 source element type,
   /// return that source element type.
   static Type *getGEPSourceElementType(const VPSingleDefRecipe *R) {
@@ -2465,8 +2461,6 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
 
   /// Check equality of underlying data of \p L and \p R.
   static bool isEqual(const VPSingleDefRecipe *L, const VPSingleDefRecipe *R) {
-    if (isSentinel(L) || isSentinel(R))
-      return L == R;
     if (L->getVPRecipeID() != R->getVPRecipeID() ||
         getOpcodeOrIntrinsicID(L) != getOpcodeOrIntrinsicID(R) ||
         getGEPSourceElementType(L) != getGEPSourceElementType(R) ||



More information about the llvm-commits mailing list