[llvm] [SelectionDAG] Avoid redundant node visits in EnforceNodeIdInvariant (PR #164834)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 23 12:12:59 PDT 2025


================
@@ -1236,13 +1236,15 @@ class ISelUpdater : public SelectionDAG::DAGUpdateListener {
 // functions.
 void SelectionDAGISel::EnforceNodeIdInvariant(SDNode *Node) {
   SmallVector<SDNode *, 4> Nodes;
+  SmallPtrSet<SDNode *, 16> Visited;
   Nodes.push_back(Node);
+  Visited.insert(Node);
 
   while (!Nodes.empty()) {
     SDNode *N = Nodes.pop_back_val();
     for (auto *U : N->users()) {
       auto UId = U->getNodeId();
-      if (UId > 0) {
+      if (UId > 0 && Visited.insert(U).second) {
----------------
topperc wrote:

I changed the code to this and the assert never failed.

```
      if (UId > 0) {
        assert(Visited.insert(U).second);
```

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


More information about the llvm-commits mailing list