[llvm] [EarlyCSE] Compare GEP instructions based on offset (PR #65875)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 06:14:55 PDT 2023
================
@@ -553,6 +553,77 @@ bool DenseMapInfo<CallValue>::isEqual(CallValue LHS, CallValue RHS) {
return LHSI->isIdenticalTo(RHSI);
}
+//===----------------------------------------------------------------------===//
+// GEPValue
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+struct GEPValue {
+ Instruction *Inst;
+ APInt ConstantOffset;
+ bool HasConstantOffset;
+
+ GEPValue(Instruction *I) : Inst(I), HasConstantOffset(false) {
+ assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
+ }
+ GEPValue(Instruction *I, APInt ConstantOffset, bool HasConstantOffset)
+ : Inst(I), ConstantOffset(ConstantOffset),
+ HasConstantOffset(HasConstantOffset) {
+ assert((isSentinel() || canHandle(I)) && "Inst can't be handled!");
+ }
+
+ bool isSentinel() const {
+ return Inst == DenseMapInfo<Instruction *>::getEmptyKey() ||
+ Inst == DenseMapInfo<Instruction *>::getTombstoneKey();
+ }
+
+ static bool canHandle(Instruction *Inst) {
+ return isa<GetElementPtrInst>(Inst);
+ }
+};
+
+} // namespace
+
+namespace llvm {
+
+template <> struct DenseMapInfo<GEPValue> {
+ static inline GEPValue getEmptyKey() {
+ return DenseMapInfo<Instruction *>::getEmptyKey();
+ }
+
+ static inline GEPValue getTombstoneKey() {
+ return DenseMapInfo<Instruction *>::getTombstoneKey();
+ }
+
+ static unsigned getHashValue(const GEPValue &Val);
+ static bool isEqual(const GEPValue &LHS, const GEPValue &RHS);
+};
+
+} // end namespace llvm
+
+unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
+ GetElementPtrInst *GEP = cast<GetElementPtrInst>(Val.Inst);
----------------
nikic wrote:
nit: Use `auto *` with `cast<>`.
https://github.com/llvm/llvm-project/pull/65875
More information about the llvm-commits
mailing list