From cefd2c3002da749d8ed1547a7f99c5384e7125a5 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Wed, 11 May 2016 21:00:33 +0000 Subject: [PATCH] SDAG: Have SelectNodeTo replace uses if it CSE's instead of morphing a node It's awkward to force callers of SelectNodeTo to figure out whether the node was morphed or CSE'd. Update uses here instead of requiring callers to (sometimes) do it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269235 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 10 +++++++--- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 7 +------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 5a61708b651..f2a38d7a3af 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5942,10 +5942,14 @@ SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, SDNode *SelectionDAG::SelectNodeTo(SDNode *N, unsigned MachineOpc, SDVTList VTs,ArrayRef Ops) { - N = MorphNodeTo(N, ~MachineOpc, VTs, Ops); + SDNode *New = MorphNodeTo(N, ~MachineOpc, VTs, Ops); // Reset the NodeID to -1. - N->setNodeId(-1); - return N; + New->setNodeId(-1); + if (New != N) { + ReplaceAllUsesWith(N, New); + RemoveDeadNode(N); + } + return New; } /// UpdadeSDLocOnMergedSDNode - If the opt level is -O0 then it throws away diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 6bb5060f5bb..9a0fd6fba6c 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -2127,12 +2127,7 @@ void SelectionDAGISel::Select_WRITE_REGISTER(SDNode *Op) { } void SelectionDAGISel::Select_UNDEF(SDNode *N) { - SDNode *New = - CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF, N->getValueType(0)); - if (New != N) { - ReplaceUses(N, New); - CurDAG->RemoveDeadNode(N); - } + CurDAG->SelectNodeTo(N, TargetOpcode::IMPLICIT_DEF, N->getValueType(0)); } /// GetVBR - decode a vbr encoding whose top bit is set.