diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp --- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp +++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp @@ -728,15 +728,8 @@ // Worklist maintains our depth-first queue of loops in this nest to process. SmallVector Worklist; - Worklist.push_back(L); - - // Walk the worklist from front to back, pushing newly found sub loops onto - // the back. This will let us process loops from back to front in depth-first - // order. We can use this simple process because loops form a tree. - for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) { - Loop *L2 = Worklist[Idx]; - Worklist.append(L2->begin(), L2->end()); - } + for_each(depth_first(L), + [&Worklist](Loop *SubLoop) { Worklist.push_back(SubLoop); }); while (!Worklist.empty()) Changed |= simplifyOneLoop(Worklist.pop_back_val(), Worklist, DT, LI, SE,