[PATCH] D86183: [NFC][DAGCombine] Remove dead node when it is created by getNegatedExpression

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 17:48:26 PDT 2020


steven.zhang created this revision.
steven.zhang added reviewers: RKSimon, spatel, efriedma, arsenm, PowerPC.
Herald added subscribers: ecnelises, wuzish, hiraditya.
Herald added a project: LLVM.
steven.zhang requested review of this revision.
Herald added a subscriber: wdng.

We hit the infinite loop reported by https://bugs.llvm.org/show_bug.cgi?id=46877 and the reason is the same as D77319 <https://reviews.llvm.org/D77319>. So we need to remove the dead node we created to avoid the sideeffect on DAGCombiner.

The reported test is huge and I think this is a NFC change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86183

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp


Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -5737,6 +5737,11 @@
       return SDValue();
   }
 
+  auto RemoveDeadNode = [&](SDValue N) {
+    if (N && N.getNode()->use_empty())
+      DAG.RemoveDeadNode(N.getNode());
+  };
+
   SDLoc DL(Op);
 
   switch (Opcode) {
@@ -5815,12 +5820,14 @@
     // Negate the X if its cost is less or equal than Y.
     if (NegX && (CostX <= CostY)) {
       Cost = CostX;
+      RemoveDeadNode(NegY);
       return DAG.getNode(ISD::FSUB, DL, VT, NegX, Y, Flags);
     }
 
     // Negate the Y if it is not expensive.
     if (NegY) {
       Cost = CostY;
+      RemoveDeadNode(NegX);
       return DAG.getNode(ISD::FSUB, DL, VT, NegY, X, Flags);
     }
     break;
@@ -5858,6 +5865,7 @@
     // Negate the X if its cost is less or equal than Y.
     if (NegX && (CostX <= CostY)) {
       Cost = CostX;
+      RemoveDeadNode(NegY);
       return DAG.getNode(Opcode, DL, VT, NegX, Y, Flags);
     }
 
@@ -5869,6 +5877,7 @@
     // Negate the Y if it is not expensive.
     if (NegY) {
       Cost = CostY;
+      RemoveDeadNode(NegX);
       return DAG.getNode(Opcode, DL, VT, X, NegY, Flags);
     }
     break;
@@ -5898,12 +5907,14 @@
     // Negate the X if its cost is less or equal than Y.
     if (NegX && (CostX <= CostY)) {
       Cost = std::min(CostX, CostZ);
+      RemoveDeadNode(NegY);
       return DAG.getNode(Opcode, DL, VT, NegX, Y, NegZ, Flags);
     }
 
     // Negate the Y if it is not expensive.
     if (NegY) {
       Cost = std::min(CostY, CostZ);
+      RemoveDeadNode(NegX);
       return DAG.getNode(Opcode, DL, VT, X, NegY, NegZ, Flags);
     }
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86183.286440.patch
Type: text/x-patch
Size: 1808 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200819/b695395c/attachment.bin>


More information about the llvm-commits mailing list