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 @@ -17666,6 +17666,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; + constexpr unsigned int MaxSteps = 8192; if (isa(Offset)) for (SDNode::use_iterator UI = BasePtr->use_begin(), UE = BasePtr->use_end(); @@ -17676,7 +17677,8 @@ 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 && @@ -17709,7 +17711,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 @@ -17883,12 +17885,13 @@ // Check for #2. SmallPtrSet Visited; SmallVector Worklist; + constexpr 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;