Relax the "don't unroll loops containing calls" rule. Instead, when a loop contains a call, lower the
unrolling threshold to the optimize-for-size threshold. Basically, for loops containing calls, unrolling
can still be profitable as long as the loop is REALLY small.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113439 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp
index f20f7dc..f0a661c 100644
--- a/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -132,8 +132,10 @@
unsigned LoopSize = ApproximateLoopSize(L, NumCalls);
DEBUG(dbgs() << " Loop Size = " << LoopSize << "\n");
if (NumCalls != 0) {
- DEBUG(dbgs() << " Not unrolling loop with function calls.\n");
- return false;
+ // Even for a loop that contains calls, it can still be profitable to
+ // unroll if the loop is really, REALLY small.
+ DEBUG(dbgs() <<" Using lower threshold for loop with function calls.\n");
+ CurrentThreshold = OptSizeUnrollThreshold;
}
uint64_t Size = (uint64_t)LoopSize*Count;
if (TripCount != 1 && Size > CurrentThreshold) {