The change fix an assert fail at ScalarEvolutionExpander.cpp (generateOverflowCheck):
const SCEV *ExitCount = SE.getPredicatedBackedgeTakenCount(AR->getLoop(), Pred); assert(ExitCount != SE.getCouldNotCompute() && "Invalid loop count");
(generateOverflowCheck is called only from expandWrapPredicate)
by inserting an early check on SCEV PredicateBackEdgeCount when createAddRecFromPHIWithCastsImpl
This assumes that L is a sub-loop of the loop being processed by the rewriter.
To make this correct you would also have to add the predicates returned by getPredicatedBackedgeTakenCount to the set of returned predicates.
I think this function might also get called from getPredicatedBackedgeTakenCount and might result in an infinite loop.
I think there is an easier solution (see the comment below).