HomePhabricator

[IndVars] Use exit count reasoning to discharge obviously untaken exits

Description

[IndVars] Use exit count reasoning to discharge obviously untaken exits

Continue in the spirit of D63618, and use exit count reasoning to prove away loop exits which can not be taken since the backedge taken count of the loop as a whole is provably less than the minimal BE count required to take this particular loop exit.

As demonstrated in the newly added tests, this triggers in a number of cases where IndVars was previously unable to discharge obviously redundant exit tests. And some not so obvious ones.

Differential Revision: https://reviews.llvm.org/D63733

Details

Event Timeline

After this revision lib/Transforms/Scalar/IndVarSimplify.cpp:2630 defines "Latch" which is only used inside an assert. This makes builds with -DNDEBUG fail with unused variable warnings.

I have committed r365943 which removes the definition of Latch and moves its logic into the assert, which cleans up the failure.