[PATCH] D77319: [DAGCombine] Remove the getNegatibleCost to avoid the out of sync with getNegatedExpression

Qing Shan Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 22:39:20 PDT 2020


steven.zhang requested review of this revision.
steven.zhang added a comment.

The root cause of the infinite loop:
As mentioned before, the new created node will be deleted later in the next iteration of the DAGCombine. And we will push all the nodes it refers into the worklist to do the combine again. So, the circle reference would happen if the referred nodes refer that node later. 
Thus, we need to remove the dead node we created immediately to avoid the side effect to DAGCombinne.

     /// This is the helper function to return the newly negated expression only
     /// when the cost is cheaper.
     SDValue getCheaperNegatedExpression(SDValue Op, SelectionDAG &DAG,
                                         bool LegalOps, bool OptForSize,
                                         unsigned Depth = 0) const {
  -    if (getNegatibleCost(Op, DAG, LegalOps, OptForSize, Depth) ==
  -        NegatibleCost::Cheaper)
  -      return negateExpression(Op, DAG, LegalOps, OptForSize, Depth);
  +    NegatibleCost Cost = NegatibleCost::Expensive;
  +    SDValue Neg =
  +        getNegatedExpression(Op, DAG, LegalOps, OptForSize, Cost, Depth);
  +    if (Neg && Cost == NegatibleCost::Cheaper)
  +      return Neg;
  +    // Remove the new created node to avoid the side effect to the DAG.
  +    if (Neg && Neg.getNode()->use_empty())
  +      DAG.RemoveDeadNode(Neg.getNode());
       return SDValue();


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77319/new/

https://reviews.llvm.org/D77319





More information about the llvm-commits mailing list