This patch tries to fully unroll loops having break statement like this
for (int i = 0; i < 8; i++) { if (a[i] == value) { found = true; break; } }
GCC can fully unroll such loops, but currently LLVM cannot because LLVM only supports loops having exact constant trip counts.
The upper bound of the trip count can be obtained from calling ScalarEvolution::getMaxBackedgeTakenCount(). Part of the patch is the refactoring work in SCEV to prevent duplicating code.
The feature of using the upper bound is enabled under the same circumstance when runtime unrolling is enabled since both are used to unroll loops without knowing the exact constant trip count.
The modified test/CodeGen/AMDGPU/tti-unroll-prefs.ll can be used as the test case of this patch.
Sorry for comment after approve.
What I see here is that TripCount could implicitly (as TripCount was passed to computeUnrollCount as a reference) become MaxTripCount. Here it is passed to UnrollLoop as TripCount.
Could you please add a comment to UnrollLoop that TripCount parameter is not always a real loop trip count, but sometimes MaxTripCount. Or rename TripCount to MaxTripCount in UnrollLoop parameters. There could be future errors if someone assumes that TripCount is exact loop trip count.