Skip to content

Conversation

@s-barannikov
Copy link
Contributor

When called from DAGCombiner, there may be a HandleSDNode allocated
on the stack. Since the node is not part of a DAG, we don't allocate
an entry for it in the operand counting map and should not attempt to
decrement its operand count.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Nov 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Sergei Barannikov (s-barannikov)

Changes

When called from DAGCombiner, there may be a HandleSDNode allocated
on the stack. Since the node is not part of a DAG, we don't allocate
an entry for it in the operand counting map and should not attempt to
decrement its operand count.


Full diff: https://github.com/llvm/llvm-project/pull/166722.diff

1 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+4-2)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index ff6a7b2cf5462..75c0cf3928719 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -12746,6 +12746,10 @@ void SelectionDAG::getTopologicallyOrderedNodes(
   for (unsigned i = 0U; i < SortedNodes.size(); ++i) {
     const SDNode *N = SortedNodes[i];
     for (const SDNode *U : N->users()) {
+      // HandleSDNode is never part of a DAG and therefor has no entry in
+      // RemainingOperands.
+      if (U->getOpcode() == ISD::HANDLENODE)
+        continue;
       unsigned &NumRemOperands = RemainingOperands[U];
       assert(NumRemOperands && "Invalid number of remaining operands");
       --NumRemOperands;
@@ -12759,8 +12763,6 @@ void SelectionDAG::getTopologicallyOrderedNodes(
          "First node in topological sort is not the entry token");
   assert(SortedNodes.front()->getNumOperands() == 0 &&
          "First node in topological sort has operands");
-  assert(SortedNodes.back()->use_empty() &&
-         "Last node in topologic sort has users");
 }
 
 /// AddDbgValue - Add a dbg_value SDNode. If SD is non-null that means the

When called from DAGCombiner, there may be a HandleSDNode allocated
on the stack. Since the node is not part of a DAG, we don't allocate
an entry for it in the operand counting map and should not attempt to
decrement its operand count.
@s-barannikov s-barannikov merged commit fca5d45 into llvm:main Nov 7, 2025
10 checks passed
@s-barannikov s-barannikov deleted the dag-topo-handle-node branch November 7, 2025 03:22
vinay-deshmukh pushed a commit to vinay-deshmukh/llvm-project that referenced this pull request Nov 8, 2025
…vm#166722)

When called from DAGCombiner, there may be a HandleSDNode allocated
on the stack. Since the node is not part of a DAG, we don't allocate
an entry for it in the operand counting map and should not attempt to
decrement its operand count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants