]> granicus.if.org Git - llvm/commitdiff
[DAG] Cleanup of unused node in SimplifySelectCC.
authorNirav Dave <niravd@google.com>
Thu, 7 Feb 2019 17:13:55 +0000 (17:13 +0000)
committerNirav Dave <niravd@google.com>
Thu, 7 Feb 2019 17:13:55 +0000 (17:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353428 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index b6023d52d6e7f90c01df77558ebb15fa7ce87fb7..33e8a79c4b95c04bd0cb2a11ccea9f981f7b89d8 100644 (file)
@@ -18660,14 +18660,21 @@ SDValue DAGCombiner::SimplifySelectCC(const SDLoc &DL, SDValue N0, SDValue N1,
   auto *N3C = dyn_cast<ConstantSDNode>(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<ConstantSDNode>(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<ConstantSDNode>(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 =