diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index ceb03eb17f6d..552ea1a5fb5e 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -605,10 +605,10 @@ bool IndVarSimplify::simplifyAndExtend(Loop *L, Intrinsic::getName(Intrinsic::experimental_guard)); bool HasGuards = GuardDecl && !GuardDecl->use_empty(); - SmallVector LoopPhis; - for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ++I) { - LoopPhis.push_back(cast(I)); - } + SmallVector LoopPhis; + for (PHINode &PN : L->getHeader()->phis()) + LoopPhis.push_back(&PN); + // Each round of simplification iterates through the SimplifyIVUsers worklist // for all current phis, then determines whether any IVs can be // widened. Widening adds new phis to LoopPhis, inducing another round of