If we can fully unroll a loop, there should be no size overhead when
rotating a loop, as a prerequisite for unrolling. Loop rotation is
conservative when optimizing for size, but we can rotate in loop-unroll,
if unrolling is beneficial.
To avoid rotating when LoopUnroll would fail, do some checks if rotating
will result in an unroll-able loop.
I measure code size on ARM64 with -Oz -flto on MultiSource, SPEC2000 and
SPEC2006. Codesize changes are as follows:
test-suite...Rodinia/backprop/backprop.test 1796.00 1752.00 -2.4%
test-suite.../Benchmarks/Olden/mst/mst.test 1436.00 1420.00 -1.1%
test-suite...006/447.dealII/447.dealII.test 256408.00 255040.00 -0.5%
test-suite...urce/Applications/lua/lua.test 88648.00 88508.00 -0.2%
test-suite.../CINT2000/176.gcc/176.gcc.test 837764.00 836520.00 -0.1%
test-suite...yApps-C++/PENNANT/PENNANT.test 40156.00 40188.00 0.1%
test-suite...rks/tramp3d-v4/tramp3d-v4.test 195420.00 195280.00 -0.1%
test-suite...0/253.perlbmk/253.perlbmk.test 335568.00 335400.00 -0.1%
Can you just use the OptForSize you defined earlier in the function?