From 24658daa730ed4fe8a53a9c899e0ba43256aedb8 Mon Sep 17 00:00:00 2001 From: Nirav Dave Date: Thu, 7 Feb 2019 17:13:55 +0000 Subject: [PATCH] [DAG] Cleanup of unused node in SimplifySelectCC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353428 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b6023d52d6e..33e8a79c4b9 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -18660,14 +18660,21 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1, auto *N3C = dyn_cast(N3.getNode()); // Determine if the condition we're dealing with is constant. - SDValue SCC = SimplifySetCC(getSetCCResultType(CmpOpVT), N0, N1, CC, DL, - false); - if (SCC.getNode()) AddToWorklist(SCC.getNode()); - - if (auto *SCCC = dyn_cast_or_null(SCC.getNode())) { - // fold select_cc true, x, y -> x - // fold select_cc false, x, y -> y - return !SCCC->isNullValue() ? N2 : N3; + if (SDValue SCC = + SimplifySetCC(getSetCCResultType(CmpOpVT), N0, N1, CC, DL, false)) { + AddToWorklist(SCC.getNode()); + if (auto *SCCC = dyn_cast(SCC.getNode())) { + // fold select_cc true, x, y -> x + // fold select_cc false, x, y -> y + bool isNull = SCCC->isNullValue(); + SDValue RV = isNull ? N3 : N2; + // Delete SCC if we don't use it. + if (SCCC != RV.getNode()) + recursivelyDeleteUnusedNodes(SCCC); + return RV; + } + // Don't combine. Cleanup SCC. + recursivelyDeleteUnusedNodes(SCC.getNode()); } if (SDValue V = -- 2.40.0