Implement new heuristic for complete loop unrolling.
authorMichael Zolotukhin <mzolotukhin@apple.com>
Thu, 5 Feb 2015 02:34:00 +0000 (02:34 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Thu, 5 Feb 2015 02:34:00 +0000 (02:34 +0000)
commit710ce5d36b44ad5bbb3cd322a6485ec170c5fcc8
treebca0ccb74c65dbd37b2da09ed75ec4fa0185f687
parentd02540a1d7d367f4f7616637606b9eaf321cf30a
Implement new heuristic for complete loop unrolling.

Complete loop unrolling can make some loads constant, thus enabling a
lot of other optimizations. To catch such cases, we look for loads that
might become constants and estimate number of instructions that would be
simplified or become dead after substitution.

Example:
Suppose we have:
int a[] = {0, 1, 0};
v = 0;
for (i = 0; i < 3; i ++)
  v += b[i]*a[i];

If we completely unroll the loop, we would get:
v = b[0]*a[0] + b[1]*a[1] + b[2]*a[2]

Which then will be simplified to:
v = b[0]* 0 + b[1]* 1 + b[2]* 0

And finally:
v = b[1]

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228265 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopUnrollPass.cpp