Index: lib/Analysis/ScalarEvolution.cpp =================================================================== --- lib/Analysis/ScalarEvolution.cpp +++ lib/Analysis/ScalarEvolution.cpp @@ -8265,7 +8265,6 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit, bool AllowPredicates) { - // This is only used for loops with a "x != y" exit test. The exit condition // is now expressed as a single expression, V = x-y. So the exit test is // effectively V != 0. We know and take advantage of the fact that this @@ -8280,6 +8279,12 @@ } const SCEVAddRecExpr *AddRec = dyn_cast(V); + if (!AddRec) { + if (const SCEVZeroExtendExpr *Z = dyn_cast(V)) + if (const SCEVAddRecExpr *A = dyn_cast(Z->getOperand())) + AddRec = A; + } + if (!AddRec && AllowPredicates) // Try to make this an AddRec using runtime tests, in the first X // iterations of this loop, where X is the SCEV expression found by the