Skip to content

Commit 960cbc5

Browse files
author
QingShan Zhang
committed
[DAGCombine] Remove dead node when it is created by getNegatedExpression
We hit the compiling time reported by https://bugs.llvm.org/show_bug.cgi?id=46877 and the reason is the same as D77319. So we need to remove the dead node we created to avoid increase the problem size of DAGCombiner. Reviewed By: Spatel Differential Revision: https://reviews.llvm.org/D86183
1 parent 41ba9d7 commit 960cbc5

File tree

2 files changed

+427
-0
lines changed

2 files changed

+427
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5737,6 +5737,11 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
57375737
return SDValue();
57385738
}
57395739

5740+
auto RemoveDeadNode = [&](SDValue N) {
5741+
if (N && N.getNode()->use_empty())
5742+
DAG.RemoveDeadNode(N.getNode());
5743+
};
5744+
57405745
SDLoc DL(Op);
57415746

57425747
switch (Opcode) {
@@ -5815,12 +5820,14 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
58155820
// Negate the X if its cost is less or equal than Y.
58165821
if (NegX && (CostX <= CostY)) {
58175822
Cost = CostX;
5823+
RemoveDeadNode(NegY);
58185824
return DAG.getNode(ISD::FSUB, DL, VT, NegX, Y, Flags);
58195825
}
58205826

58215827
// Negate the Y if it is not expensive.
58225828
if (NegY) {
58235829
Cost = CostY;
5830+
RemoveDeadNode(NegX);
58245831
return DAG.getNode(ISD::FSUB, DL, VT, NegY, X, Flags);
58255832
}
58265833
break;
@@ -5858,6 +5865,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
58585865
// Negate the X if its cost is less or equal than Y.
58595866
if (NegX && (CostX <= CostY)) {
58605867
Cost = CostX;
5868+
RemoveDeadNode(NegY);
58615869
return DAG.getNode(Opcode, DL, VT, NegX, Y, Flags);
58625870
}
58635871

@@ -5869,6 +5877,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
58695877
// Negate the Y if it is not expensive.
58705878
if (NegY) {
58715879
Cost = CostY;
5880+
RemoveDeadNode(NegX);
58725881
return DAG.getNode(Opcode, DL, VT, X, NegY, Flags);
58735882
}
58745883
break;
@@ -5898,12 +5907,14 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
58985907
// Negate the X if its cost is less or equal than Y.
58995908
if (NegX && (CostX <= CostY)) {
59005909
Cost = std::min(CostX, CostZ);
5910+
RemoveDeadNode(NegY);
59015911
return DAG.getNode(Opcode, DL, VT, NegX, Y, NegZ, Flags);
59025912
}
59035913

59045914
// Negate the Y if it is not expensive.
59055915
if (NegY) {
59065916
Cost = std::min(CostY, CostZ);
5917+
RemoveDeadNode(NegX);
59075918
return DAG.getNode(Opcode, DL, VT, X, NegY, NegZ, Flags);
59085919
}
59095920
break;

0 commit comments

Comments
 (0)