diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -17627,6 +17627,7 @@ // can be folded with this one. We should do this to avoid having to keep // a copy of the original base pointer. SmallVector OtherUses; + const unsigned int MaxSteps = 8192; if (isa(Offset)) for (SDNode::use_iterator UI = BasePtr->use_begin(), UE = BasePtr->use_end(); @@ -17637,7 +17638,7 @@ if (Use.getUser() == Ptr.getNode() || Use != BasePtr) continue; - if (SDNode::hasPredecessorHelper(Use.getUser(), Visited, Worklist)) + if (SDNode::hasPredecessorHelper(Use.getUser(), Visited, Worklist, MaxSteps)) continue; if (Use.getUser()->getOpcode() != ISD::ADD && @@ -17670,7 +17671,7 @@ for (SDNode *Use : Ptr->uses()) { if (Use == N) continue; - if (SDNode::hasPredecessorHelper(Use, Visited, Worklist)) + if (SDNode::hasPredecessorHelper(Use, Visited, Worklist, MaxSteps)) return false; // If Ptr may be folded in addressing mode of other use, then it's @@ -17844,12 +17845,13 @@ // Check for #2. SmallPtrSet Visited; SmallVector Worklist; + const unsigned int MaxSteps = 8192; // Ptr is predecessor to both N and Op. Visited.insert(Ptr.getNode()); Worklist.push_back(N); Worklist.push_back(Op); - if (!SDNode::hasPredecessorHelper(N, Visited, Worklist) && - !SDNode::hasPredecessorHelper(Op, Visited, Worklist)) + if (!SDNode::hasPredecessorHelper(N, Visited, Worklist, MaxSteps) && + !SDNode::hasPredecessorHelper(Op, Visited, Worklist, MaxSteps)) return Op; } return nullptr;