From: Justin Bogner Date: Fri, 6 May 2016 18:42:16 +0000 (+0000) Subject: SDAG: Don't leave dangling dead nodes after SelectCodeCommon X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=040794426987a0e673a09623514ad18c585321df;p=llvm SDAG: Don't leave dangling dead nodes after SelectCodeCommon Relying on the caller to clean up after we've replaced all uses of a node won't work when we've migrated to the `void Select(...)` API. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268774 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 0aafbbae6db..a036a31c317 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -2179,7 +2179,7 @@ void SelectionDAGISel::UpdateChains( CurDAG->ReplaceAllUsesOfValueWith(ChainVal, InputChain); // If the node became dead and we haven't already seen it, delete it. - if (ChainNode->use_empty() && + if (ChainNode != NodeToMatch && ChainNode->use_empty() && !std::count(NowDeadNodes.begin(), NowDeadNodes.end(), ChainNode)) NowDeadNodes.push_back(ChainNode); } @@ -2741,6 +2741,7 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, case ISD::AssertZext: CurDAG->ReplaceAllUsesOfValueWith(SDValue(NodeToMatch, 0), NodeToMatch->getOperand(0)); + CurDAG->RemoveDeadNode(NodeToMatch); return nullptr; case ISD::INLINEASM: return Select_INLINEASM(NodeToMatch); case ISD::READ_REGISTER: return Select_READ_REGISTER(NodeToMatch); @@ -3474,6 +3475,7 @@ SelectCodeCommon(SDNode *NodeToMatch, const unsigned char *MatcherTable, assert(NodeToMatch->use_empty() && "Didn't replace all uses of the node?"); + CurDAG->RemoveDeadNode(NodeToMatch); // FIXME: We just return here, which interacts correctly with SelectRoot // above. We should fix this to not return an SDNode* anymore.