@@ -5737,6 +5737,11 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5737
5737
return SDValue ();
5738
5738
}
5739
5739
5740
+ auto RemoveDeadNode = [&](SDValue N) {
5741
+ if (N && N.getNode ()->use_empty ())
5742
+ DAG.RemoveDeadNode (N.getNode ());
5743
+ };
5744
+
5740
5745
SDLoc DL (Op);
5741
5746
5742
5747
switch (Opcode) {
@@ -5815,12 +5820,14 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5815
5820
// Negate the X if its cost is less or equal than Y.
5816
5821
if (NegX && (CostX <= CostY)) {
5817
5822
Cost = CostX;
5823
+ RemoveDeadNode (NegY);
5818
5824
return DAG.getNode (ISD::FSUB, DL, VT, NegX, Y, Flags);
5819
5825
}
5820
5826
5821
5827
// Negate the Y if it is not expensive.
5822
5828
if (NegY) {
5823
5829
Cost = CostY;
5830
+ RemoveDeadNode (NegX);
5824
5831
return DAG.getNode (ISD::FSUB, DL, VT, NegY, X, Flags);
5825
5832
}
5826
5833
break ;
@@ -5858,6 +5865,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5858
5865
// Negate the X if its cost is less or equal than Y.
5859
5866
if (NegX && (CostX <= CostY)) {
5860
5867
Cost = CostX;
5868
+ RemoveDeadNode (NegY);
5861
5869
return DAG.getNode (Opcode, DL, VT, NegX, Y, Flags);
5862
5870
}
5863
5871
@@ -5869,6 +5877,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5869
5877
// Negate the Y if it is not expensive.
5870
5878
if (NegY) {
5871
5879
Cost = CostY;
5880
+ RemoveDeadNode (NegX);
5872
5881
return DAG.getNode (Opcode, DL, VT, X, NegY, Flags);
5873
5882
}
5874
5883
break ;
@@ -5898,12 +5907,14 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5898
5907
// Negate the X if its cost is less or equal than Y.
5899
5908
if (NegX && (CostX <= CostY)) {
5900
5909
Cost = std::min (CostX, CostZ);
5910
+ RemoveDeadNode (NegY);
5901
5911
return DAG.getNode (Opcode, DL, VT, NegX, Y, NegZ, Flags);
5902
5912
}
5903
5913
5904
5914
// Negate the Y if it is not expensive.
5905
5915
if (NegY) {
5906
5916
Cost = std::min (CostY, CostZ);
5917
+ RemoveDeadNode (NegX);
5907
5918
return DAG.getNode (Opcode, DL, VT, X, NegY, NegZ, Flags);
5908
5919
}
5909
5920
break ;
0 commit comments