Index: llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp =================================================================== --- llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -122,6 +122,11 @@ cl::desc( "Set the max unroll count for full unrolling, for testing purposes")); +static cl::opt UnrollFullSizeThreshold( + "unroll-full-size-threshold", cl::init(1000), cl::Hidden, + cl::desc( + "Set the size threshold for full unrolling, for testing purposes")); + static cl::opt UnrollAllowPartial("unroll-allow-partial", cl::Hidden, cl::desc("Allows loops to be partially unrolled until " @@ -1120,6 +1125,11 @@ return LoopUnrollResult::Unmodified; } + if (LoopSize > UnrollFullSizeThreshold) { + LLVM_DEBUG(dbgs() << " Not unrolling loop with as large loop size.\n"); + return LoopUnrollResult::Unmodified; + } + // Find the smallest exact trip count for any exit. This is an upper bound // on the loop trip count, but an exit at an earlier iteration is still // possible. An unroll by the smallest exact trip count guarantees that all