[llvm] [SelectionDAG][NVPTX] Allow targets to configure CSE strategy (PR #192812)

via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 18 15:38:33 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Princeton Ferro (Prince781)

<details>
<summary>Changes</summary>

To improve the debugging experience at `-O0`, CUDA avoids folding nodes with different debug info. This patch introduces a system that allows targets to configure how SelectionDAG CSE's nodes. We add a strategy for NVPTX and a default strategy that leaves the CSE behavior unchanged for other targets.

---

Patch is 53.21 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/192812.diff


10 Files Affected:

- (modified) llvm/include/llvm/CodeGen/SelectionDAG.h (+28-12) 
- (modified) llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h (+7) 
- (modified) llvm/include/llvm/IR/DebugLoc.h (+4) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+139-126) 
- (modified) llvm/lib/IR/DebugLoc.cpp (+8) 
- (modified) llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.cpp (+80) 
- (modified) llvm/lib/Target/NVPTX/NVPTXSelectionDAGInfo.h (+3) 
- (added) llvm/test/DebugInfo/NVPTX/cse-opt.ll (+34) 
- (added) llvm/test/DebugInfo/NVPTX/cse-same-loc.ll (+33) 
- (added) llvm/test/DebugInfo/NVPTX/no-cse-diff-loc.ll (+32) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h
index df4cac1caf7fd..34cb9e448bbb1 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAG.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -46,6 +46,7 @@
 #include <cstdint>
 #include <functional>
 #include <map>
+#include <memory>
 #include <set>
 #include <string>
 #include <tuple>
@@ -216,6 +217,26 @@ class SDDbgInfo {
 
 LLVM_ABI void checkForCycles(const SelectionDAG *DAG, bool force = false);
 
+/// Abstract CSE map for SDNodes.  Targets can override
+/// SelectionDAGTargetInfo::createCSEMap() to supply a custom implementation.
+class SDNodeCSEMap {
+public:
+  virtual ~SDNodeCSEMap() = default;
+
+  /// Look up ID in the CSE map, or prepare an insertion point.
+  /// Opcode and DL are forwarded so the implementation can apply
+  /// target-specific CSE policies.
+  virtual SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID,
+                                      unsigned Opcode, const SDLoc &DL,
+                                      void *&InsertPos) = 0;
+  virtual void InsertNode(SDNode *N, void *InsertPos) = 0;
+  /// Returns true if N was present.
+  virtual bool RemoveNode(SDNode *N) = 0;
+  /// Insert N, or return the existing equal node.
+  virtual SDNode *GetOrInsertNode(SDNode *N) = 0;
+  virtual void clear() = 0;
+};
+
 /// This is used to represent a portion of an LLVM function in a low-level
 /// Data Dependence DAG representation suitable for instruction selection.
 /// This DAG is constructed as the first step of instruction selection in order
@@ -280,9 +301,9 @@ class SelectionDAG {
   /// Pool allocation for nodes.
   NodeAllocatorType NodeAllocator;
 
-  /// This structure is used to memoize nodes, automatically performing
-  /// CSE with existing nodes when a duplicate is requested.
-  FoldingSet<SDNode> CSEMap;
+  /// CSE map for SDNode deduplication; created by
+  /// SelectionDAGTargetInfo::createCSEMap().
+  std::unique_ptr<SDNodeCSEMap> CSEMap;
 
   /// Pool allocation for machine-opcode SDNode operands.
   BumpPtrAllocator OperandAllocator;
@@ -2783,16 +2804,11 @@ class SelectionDAG {
   void allnodes_clear();
 
   /// Look up the node specified by ID in CSEMap.  If it exists, return it.  If
-  /// not, return the insertion token that will make insertion faster.  This
-  /// overload is for nodes other than Constant or ConstantFP, use the other one
-  /// for those.
-  SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
-
-  /// Look up the node specified by ID in CSEMap.  If it exists, return it.  If
-  /// not, return the insertion token that will make insertion faster.  Performs
-  /// additional processing for constant nodes.
+  /// not, return the insertion token that will make insertion faster.
+  /// Opcode is used by target CSE policies to apply node-kind-specific rules.
+  /// Use SDLoc() for DL when there is no associated debug location.
   SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
-                              void *&InsertPos);
+                              void *&InsertPos, unsigned Opcode);
 
   /// Maps to auto-CSE operations.
   std::vector<CondCodeSDNode*> CondCodeNodes;
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h b/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
index 64f63d5b2190f..7d8375c1f32bb 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGTargetInfo.h
@@ -19,11 +19,13 @@
 #include "llvm/CodeGen/SDNodeInfo.h"
 #include "llvm/CodeGen/SelectionDAGNodes.h"
 #include "llvm/Support/CodeGen.h"
+#include <memory>
 #include <utility>
 
 namespace llvm {
 
 class CallInst;
+class SDNodeCSEMap;
 class SelectionDAG;
 
 //===----------------------------------------------------------------------===//
@@ -204,6 +206,11 @@ class SelectionDAGTargetInfo {
   virtual bool disableGenericCombines(CodeGenOptLevel OptLevel) const {
     return false;
   }
+
+  /// Returns the CSE map to use for this SelectionDAG.
+  /// Called once during SelectionDAG::init().
+  LLVM_ABI virtual std::unique_ptr<SDNodeCSEMap>
+  createCSEMap(SelectionDAG &DAG) const;
 };
 
 /// Proxy class that targets should inherit from if they wish to use
diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h
index 484adbb6e6a6c..c501f4bb4dc70 100644
--- a/llvm/include/llvm/IR/DebugLoc.h
+++ b/llvm/include/llvm/IR/DebugLoc.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_IR_DEBUGLOC_H
 #define LLVM_IR_DEBUGLOC_H
 
+#include "llvm/ADT/FoldingSet.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/TrackingMDRef.h"
 #include "llvm/Support/Compiler.h"
@@ -293,6 +294,9 @@ class DebugLoc {
   LLVM_ABI bool isImplicitCode() const;
   LLVM_ABI void setImplicitCode(bool ImplicitCode);
 
+  /// Add the filename, line, and column to ID.
+  LLVM_ABI void Profile(FoldingSetNodeID &ID) const;
+
   bool operator==(const DebugLoc &DL) const { return Loc == DL.Loc; }
   bool operator!=(const DebugLoc &DL) const { return Loc != DL.Loc; }
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 86245e4044925..6ef51b5133164 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -84,6 +84,32 @@
 using namespace llvm;
 using namespace llvm::SDPatternMatch;
 
+namespace {
+/// Default CSE map: thin wrapper around FoldingSet<SDNode>.
+class DefaultSDNodeMap final : public SDNodeCSEMap {
+  FoldingSet<SDNode> FS;
+
+public:
+  SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, unsigned /*Opcode*/,
+                              const SDLoc & /*DL*/, void *&InsertPos) override {
+    return FS.FindNodeOrInsertPos(ID, InsertPos);
+  }
+  void InsertNode(SDNode *N, void *InsertPos) override {
+    FS.InsertNode(N, InsertPos);
+  }
+  bool RemoveNode(SDNode *N) override { return FS.RemoveNode(N); }
+  SDNode *GetOrInsertNode(SDNode *N) override {
+    return FS.GetOrInsertNode(N);
+  }
+  void clear() override { FS.clear(); }
+};
+} // namespace
+
+std::unique_ptr<SDNodeCSEMap>
+SelectionDAGTargetInfo::createCSEMap(SelectionDAG &) const {
+  return std::make_unique<DefaultSDNodeMap>();
+}
+
 /// makeVTList - Return an instance of the SDVTList struct initialized with the
 /// specified members.
 static SDVTList makeVTList(const EVT *VTs, unsigned NumVTs) {
@@ -1300,7 +1326,7 @@ bool SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
     // Remove it from the CSE Map.
     assert(N->getOpcode() != ISD::DELETED_NODE && "DELETED_NODE in CSEMap!");
     assert(N->getOpcode() != ISD::EntryToken && "EntryToken in CSEMap!");
-    Erased = CSEMap.RemoveNode(N);
+    Erased = CSEMap->RemoveNode(N);
     break;
   }
 #ifndef NDEBUG
@@ -1326,7 +1352,7 @@ SelectionDAG::AddModifiedNodeToCSEMaps(SDNode *N) {
   // For node types that aren't CSE'd, just act as if no identical node
   // already exists.
   if (!doNotCSE(N)) {
-    SDNode *Existing = CSEMap.GetOrInsertNode(N);
+    SDNode *Existing = CSEMap->GetOrInsertNode(N);
     if (Existing != N) {
       // If there was already an existing matching node, use ReplaceAllUsesWith
       // to replace the dead one with the existing one.  This can cause
@@ -1362,7 +1388,7 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDValue Op,
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
-  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos);
+  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos, N->getOpcode());
   if (Node)
     Node->intersectFlagsWith(N->getFlags());
   return Node;
@@ -1382,7 +1408,7 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N,
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
-  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos);
+  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos, N->getOpcode());
   if (Node)
     Node->intersectFlagsWith(N->getFlags());
   return Node;
@@ -1400,7 +1426,7 @@ SDNode *SelectionDAG::FindModifiedNodeSlot(SDNode *N, ArrayRef<SDValue> Ops,
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, N->getOpcode(), N->getVTList(), Ops);
   AddNodeIDCustom(ID, N);
-  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos);
+  SDNode *Node = FindNodeOrInsertPos(ID, SDLoc(N), InsertPos, N->getOpcode());
   if (Node)
     Node->intersectFlagsWith(N->getFlags());
   return Node;
@@ -1434,6 +1460,7 @@ void SelectionDAG::init(MachineFunction &NewMF,
   ORE = &NewORE;
   TLI = getSubtarget().getTargetLowering();
   TSI = getSubtarget().getSelectionDAGInfo();
+  CSEMap = TSI->createCSEMap(*this);
   LibInfo = LibraryInfo;
   Libcalls = LibcallsInfo;
   Context = &MF->getFunction().getContext();
@@ -1466,23 +1493,9 @@ void SelectionDAG::allnodes_clear() {
 }
 
 SDNode *SelectionDAG::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
-                                          void *&InsertPos) {
-  SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
-  if (N) {
-    switch (N->getOpcode()) {
-    default: break;
-    case ISD::Constant:
-    case ISD::ConstantFP:
-      llvm_unreachable("Querying for Constant and ConstantFP nodes requires "
-                       "debug location.  Use another overload.");
-    }
-  }
-  return N;
-}
-
-SDNode *SelectionDAG::FindNodeOrInsertPos(const FoldingSetNodeID &ID,
-                                          const SDLoc &DL, void *&InsertPos) {
-  SDNode *N = CSEMap.FindNodeOrInsertPos(ID, InsertPos);
+                                          const SDLoc &DL, void *&InsertPos,
+                                          unsigned Opcode) {
+  SDNode *N = CSEMap->FindNodeOrInsertPos(ID, Opcode, DL, InsertPos);
   if (N) {
     switch (N->getOpcode()) {
     case ISD::Constant:
@@ -1509,7 +1522,7 @@ void SelectionDAG::clear() {
   allnodes_clear();
   OperandRecycler.clear(OperandAllocator);
   OperandAllocator.Reset();
-  CSEMap.clear();
+  CSEMap->clear();
 
   ExtendedValueTypeNodes.clear();
   ExternalSymbols.clear();
@@ -1833,13 +1846,13 @@ SDValue SelectionDAG::getConstant(const ConstantInt &Val, const SDLoc &DL,
   ID.AddBoolean(isO);
   void *IP = nullptr;
   SDNode *N = nullptr;
-  if ((N = FindNodeOrInsertPos(ID, DL, IP)))
+  if ((N = FindNodeOrInsertPos(ID, DL, IP, Opc)))
     if (!VT.isVector())
       return SDValue(N, 0);
 
   if (!N) {
     N = newSDNode<ConstantSDNode>(isT, isO, Elt, VTs);
-    CSEMap.InsertNode(N, IP);
+    CSEMap->InsertNode(N, IP);
     InsertNode(N);
     NewSDValueDbgMsg(SDValue(N, 0), "Creating constant: ", this);
   }
@@ -1912,13 +1925,13 @@ SDValue SelectionDAG::getConstantFP(const ConstantFP &V, const SDLoc &DL,
   ID.AddPointer(Elt);
   void *IP = nullptr;
   SDNode *N = nullptr;
-  if ((N = FindNodeOrInsertPos(ID, DL, IP)))
+  if ((N = FindNodeOrInsertPos(ID, DL, IP, Opc)))
     if (!VT.isVector())
       return SDValue(N, 0);
 
   if (!N) {
     N = newSDNode<ConstantFPSDNode>(isTarget, Elt, VTs);
-    CSEMap.InsertNode(N, IP);
+    CSEMap->InsertNode(N, IP);
     InsertNode(N);
   }
 
@@ -1971,12 +1984,12 @@ SDValue SelectionDAG::getGlobalAddress(const GlobalValue *GV, const SDLoc &DL,
   ID.AddInteger(Offset);
   ID.AddInteger(TargetFlags);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<GlobalAddressSDNode>(
       Opc, DL.getIROrder(), DL.getDebugLoc(), GV, VTs, Offset, TargetFlags);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
     InsertNode(N);
   return SDValue(N, 0);
 }
@@ -1987,11 +2000,11 @@ SDValue SelectionDAG::getDeactivationSymbol(const GlobalValue *GV) {
   AddNodeIDNode(ID, ISD::DEACTIVATION_SYMBOL, VTs, {});
   ID.AddPointer(GV);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::DEACTIVATION_SYMBOL))
     return SDValue(E, 0);
 
   auto *N = newSDNode<DeactivationSymbolSDNode>(GV, VTs);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2003,11 +2016,11 @@ SDValue SelectionDAG::getFrameIndex(int FI, EVT VT, bool isTarget) {
   AddNodeIDNode(ID, Opc, VTs, {});
   ID.AddInteger(FI);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<FrameIndexSDNode>(FI, VTs, isTarget);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2023,11 +2036,11 @@ SDValue SelectionDAG::getJumpTable(int JTI, EVT VT, bool isTarget,
   ID.AddInteger(JTI);
   ID.AddInteger(TargetFlags);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<JumpTableSDNode>(JTI, VTs, isTarget, TargetFlags);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2057,12 +2070,12 @@ SDValue SelectionDAG::getConstantPool(const Constant *C, EVT VT,
   ID.AddPointer(C);
   ID.AddInteger(TargetFlags);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<ConstantPoolSDNode>(isTarget, C, VTs, Offset, *Alignment,
                                           TargetFlags);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   SDValue V = SDValue(N, 0);
   NewSDValueDbgMsg(V, "Creating new constant pool: ", this);
@@ -2085,12 +2098,12 @@ SDValue SelectionDAG::getConstantPool(MachineConstantPoolValue *C, EVT VT,
   C->addSelectionDAGCSEId(ID);
   ID.AddInteger(TargetFlags);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<ConstantPoolSDNode>(isTarget, C, VTs, Offset, *Alignment,
                                           TargetFlags);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2100,11 +2113,11 @@ SDValue SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) {
   AddNodeIDNode(ID, ISD::BasicBlock, getVTList(MVT::Other), {});
   ID.AddPointer(MBB);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::BasicBlock))
     return SDValue(E, 0);
 
   auto *N = newSDNode<BasicBlockSDNode>(MBB);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2399,7 +2412,7 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
     ID.AddInteger(MaskVec[i]);
 
   void* IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP, ISD::VECTOR_SHUFFLE))
     return SDValue(E, 0);
 
   // Allocate the mask array for the node out of the BumpPtrAllocator, since
@@ -2412,7 +2425,7 @@ SDValue SelectionDAG::getVectorShuffle(EVT VT, const SDLoc &dl, SDValue N1,
                                            dl.getDebugLoc(), MaskAlloc);
   createOperands(N, Ops);
 
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   SDValue V = SDValue(N, 0);
   NewSDValueDbgMsg(V, "Creating new node: ", this);
@@ -2435,12 +2448,12 @@ SDValue SelectionDAG::getRegister(Register Reg, EVT VT) {
   AddNodeIDNode(ID, ISD::Register, VTs, {});
   ID.AddInteger(Reg.id());
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::Register))
     return SDValue(E, 0);
 
   auto *N = newSDNode<RegisterSDNode>(Reg, VTs);
   N->SDNodeBits.IsDivergent = TLI->isSDNodeSourceOfDivergence(N, FLI, UA);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2450,11 +2463,11 @@ SDValue SelectionDAG::getRegisterMask(const uint32_t *RegMask) {
   AddNodeIDNode(ID, ISD::RegisterMask, getVTList(MVT::Untyped), {});
   ID.AddPointer(RegMask);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::RegisterMask))
     return SDValue(E, 0);
 
   auto *N = newSDNode<RegisterMaskSDNode>(RegMask);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2471,14 +2484,14 @@ SDValue SelectionDAG::getLabelNode(unsigned Opcode, const SDLoc &dl,
   AddNodeIDNode(ID, Opcode, getVTList(MVT::Other), Ops);
   ID.AddPointer(Label);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opcode))
     return SDValue(E, 0);
 
   auto *N =
       newSDNode<LabelSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(), Label);
   createOperands(N, Ops);
 
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2495,11 +2508,11 @@ SDValue SelectionDAG::getBlockAddress(const BlockAddress *BA, EVT VT,
   ID.AddInteger(Offset);
   ID.AddInteger(TargetFlags);
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, Opc))
     return SDValue(E, 0);
 
   auto *N = newSDNode<BlockAddressSDNode>(Opc, VTs, BA, Offset, TargetFlags);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2510,11 +2523,11 @@ SDValue SelectionDAG::getSrcValue(const Value *V) {
   ID.AddPointer(V);
 
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::SRCVALUE))
     return SDValue(E, 0);
 
   auto *N = newSDNode<SrcValueSDNode>(V);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2525,11 +2538,11 @@ SDValue SelectionDAG::getMDNode(const MDNode *MD) {
   ID.AddPointer(MD);
 
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP, ISD::MDNODE_SDNODE))
     return SDValue(E, 0);
 
   auto *N = newSDNode<MDNodeSDNode>(MD);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -2551,14 +2564,14 @@ SDValue SelectionDAG::getAddrSpaceCast(const SDLoc &dl, EVT VT, SDValue Ptr,
   ID.AddInteger(DestAS);
 
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP, ISD::ADDRSPACECAST))
     return SDValue(E, 0);
 
   auto *N = newSDNode<AddrSpaceCastSDNode>(dl.getIROrder(), dl.getDebugLoc(),
                                            VTs, SrcAS, DestAS);
   createOperands(N, Ops);
 
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
   InsertNode(N);
   return SDValue(N, 0);
 }
@@ -6872,11 +6885,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT) {
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, Opcode, VTs, {});
   void *IP = nullptr;
-  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP))
+  if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, Opcode))
     return SDValue(E, 0);
 
   auto *N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
-  CSEMap.InsertNode(N, IP);
+  CSEMap->InsertNode(N, IP);
 
   InsertNode(N);
   SDValue V = SDValue(N, 0);
@@ -7253,7 +7266,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     FoldingSetNodeID ID;
     AddNodeIDNode(ID, Opcode, VTs, Ops);
     void *IP = nullptr;
-    if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
+    if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP, Opcode)) {
       E->intersectFlagsWith(Flags);
       return SDValue(E, 0);
     }
@@ -7261,7 +7274,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
     N->setFlags(Flags);
     createOperands(N, Ops);
-    CSEMap.InsertNode(N, IP);
+    CSEMap->InsertNode(N, IP);
   } else {
     N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
     createOper...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/192812


More information about the llvm-commits mailing list