From: Nirav Dave Date: Fri, 29 Mar 2019 20:26:23 +0000 (+0000) Subject: [DAGCombiner] Rewrite ImproveLifetimeNodeChain to avoid DAG loop. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8ac9101a1760695c35d324b4c238c2b4d095e50;p=llvm [DAGCombiner] Rewrite ImproveLifetimeNodeChain to avoid DAG loop. Avoid EXPENSIVE_CHECK failure. NFCI. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357309 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 13e1e96cc92..2442d20b5ca 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15709,14 +15709,15 @@ SDValue DAGCombiner::ImproveLifetimeNodeChain(SDNode *N) { auto Chain = N->getOperand(0); auto NewChain = FindBetterChain(N, Chain); if (NewChain != Chain) { - SDNode *N2 = DAG.UpdateNodeOperands(N, NewChain, N->getOperand(1)); - // Make sure users of new N still depend on Chain - auto TF = DAG.getNode(ISD::TokenFactor, SDLoc(N2), MVT::Other, Chain, - SDValue(N2, 0)); - DAG.ReplaceAllUsesOfValueWith(SDValue(N2, 0), TF); - AddToWorklist(DAG.UpdateNodeOperands(TF.getNode(), Chain, SDValue(N2, 0))); - AddToWorklist(N2); - return SDValue(N, 0); + LifetimeSDNode *LN = cast(N); + // Create New Node to prevent loop in CombineTo. + SDValue NewN = DAG.getLifetimeNode(N->getOpcode() == ISD::LIFETIME_START, + SDLoc(N), NewChain, LN->getFrameIndex(), + LN->hasOffset() ? LN->getSize() : -1, + LN->hasOffset() ? LN->getOffset() : -1); + AddToWorklist(NewN.getNode()); + auto TF = DAG.getNode(ISD::TokenFactor, SDLoc(N), MVT::Other, Chain, NewN); + return CombineTo(N, TF); } return SDValue(); }