[LoopUnroll] Fix the partial unrolling threshold for small loop sizes
authorHal Finkel <hfinkel@anl.gov>
Sat, 10 Jan 2015 00:30:55 +0000 (00:30 +0000)
committerHal Finkel <hfinkel@anl.gov>
Sat, 10 Jan 2015 00:30:55 +0000 (00:30 +0000)
commita14d6f1ea5f96172d1d421dec2c6020a60be0729
tree4711f80e751116229a953047cae877751729241d
parent68016e0a6e68335f6b9bff3cccd4f97bd82872dd
[LoopUnroll] Fix the partial unrolling threshold for small loop sizes

When we compute the size of a loop, we include the branch on the backedge and
the comparison feeding the conditional branch. Under normal circumstances,
these don't get replicated with the rest of the loop body when we unroll. This
led to the somewhat surprising behavior that really small loops would not get
unrolled enough -- they could be unrolled more and the resulting loop would be
below the threshold, because we were assuming they'd take
(LoopSize * UnrollingFactor) instructions after unrolling, instead of
(((LoopSize-2) * UnrollingFactor)+2) instructions. This fixes that computation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225565 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopUnrollPass.cpp
test/Transforms/LoopUnroll/partial-unroll-optsize.ll
test/Transforms/LoopUnroll/runtime-loop2.ll