llvm-6502/lib/Transforms/Scalar
Hal Finkel bebe48dbfe Add a loop rerolling pass
This adds a loop rerolling pass: the opposite of (partial) loop unrolling. The
transformation aims to take loops like this:

for (int i = 0; i < 3200; i += 5) {
  a[i]     += alpha * b[i];
  a[i + 1] += alpha * b[i + 1];
  a[i + 2] += alpha * b[i + 2];
  a[i + 3] += alpha * b[i + 3];
  a[i + 4] += alpha * b[i + 4];
}

and turn them into this:

for (int i = 0; i < 3200; ++i) {
  a[i] += alpha * b[i];
}

and loops like this:

for (int i = 0; i < 500; ++i) {
  x[3*i] = foo(0);
  x[3*i+1] = foo(0);
  x[3*i+2] = foo(0);
}

and turn them into this:

for (int i = 0; i < 1500; ++i) {
  x[i] = foo(0);
}

There are two motivations for this transformation:

  1. Code-size reduction (especially relevant, obviously, when compiling for
code size).

  2. Providing greater choice to the loop vectorizer (and generic unroller) to
choose the unrolling factor (and a better ability to vectorize). The loop
vectorizer can take vector lengths and register pressure into account when
choosing an unrolling factor, for example, and a pre-unrolled loop limits that
choice. This is especially problematic if the manual unrolling was optimized
for a machine different from the current target.

The current implementation is limited to single basic-block loops only. The
rerolling recognition should work regardless of how the loop iterations are
intermixed within the loop body (subject to dependency and side-effect
constraints), but the significant restriction is that the order of the
instructions in each iteration must be identical. This seems sufficient to
capture all current use cases.

This pass is not currently enabled by default at any optimization level.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194939 91177308-0d34-0410-b5e6-96231b3b80d8
2013-11-16 23:59:05 +00:00
..
ADCE.cpp Use SmallVectorImpl::iterator/const_iterator instead of SmallVector to avoid specifying the vector size. 2013-07-04 01:31:24 +00:00
CMakeLists.txt Add a loop rerolling pass 2013-11-16 23:59:05 +00:00
CodeGenPrepare.cpp Remove the very substantial, largely unmaintained legacy PGO 2013-10-02 15:42:23 +00:00
ConstantProp.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
CorrelatedValuePropagation.cpp CVP: If we have a PHI with an incoming select, try to skip the select. 2013-02-24 15:34:43 +00:00
DCE.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
DeadStoreElimination.cpp Change GetPointerBaseWithConstantOffset's DataLayout argument from a 2013-01-31 02:00:45 +00:00
EarlyCSE.cpp Get rid of unused isPodLike definitions. 2013-09-11 00:36:54 +00:00
FlattenCFGPass.cpp Factor FlattenCFG out from SimplifyCFG 2013-08-06 02:43:45 +00:00
GlobalMerge.cpp Change tabs to spaces. 2013-07-22 21:11:30 +00:00
GVN.cpp Correct a glitch in r194424 which may invalidate iterator. 2013-11-12 08:33:03 +00:00
IndVarSimplify.cpp Fix SCEVExpander: don't try to expand quadratic recurrences outside a loop. 2013-10-25 21:35:56 +00:00
JumpThreading.cpp Don't eliminate a partially redundant load if it's in a landing pad. 2013-10-21 04:09:17 +00:00
LICM.cpp LICM: Hoist insertvalue/extractvalue out of loops. 2013-01-09 18:12:03 +00:00
LLVMBuild.txt LLVMBuild: Remove trailing newline, which irked me. 2011-12-12 19:48:00 +00:00
LoopDeletion.cpp Use SmallVectorImpl& instead of SmallVector to avoid repeating small vector size. 2013-07-14 04:42:23 +00:00
LoopIdiomRecognize.cpp Even more spelling fixes for "instruction". 2013-09-28 13:42:22 +00:00
LoopInstSimplify.cpp Remove #includes from the commonly used LoopInfo.h. 2013-02-09 01:04:28 +00:00
LoopRerollPass.cpp Add a loop rerolling pass 2013-11-16 23:59:05 +00:00
LoopRotation.cpp Rotate multi-exit loops even if the latch was simplified. 2013-05-06 17:58:18 +00:00
LoopStrengthReduce.cpp Fix SCEVExpander: don't try to expand quadratic recurrences outside a loop. 2013-10-25 21:35:56 +00:00
LoopUnrollPass.cpp Add a runtime unrolling parameter to the LoopUnroll pass constructor 2013-11-05 00:08:03 +00:00
LoopUnswitch.cpp Remove dead code from LoopUnswitch 2013-11-08 19:58:21 +00:00
LowerAtomic.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
Makefile
MemCpyOptimizer.cpp MemCpyOptimizer: Use max legal int size instead of pointer size 2013-09-16 22:43:16 +00:00
PartiallyInlineLibCalls.cpp Turn MipsOptimizeMathLibCalls into a target-independent scalar transform 2013-08-23 10:27:02 +00:00
Reassociate.cpp Use switch instead of if. No functionality change. 2013-07-22 23:38:16 +00:00
Reg2Mem.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
SampleProfile.cpp Fix -Wdelete-non-virtual-dtor warnings by making SampleProfile methods non-virtual 2013-11-13 13:09:39 +00:00
Scalar.cpp Add a loop rerolling pass 2013-11-16 23:59:05 +00:00
ScalarReplAggregates.cpp Teach scalarrepl about address spaces 2013-10-30 22:54:58 +00:00
SCCP.cpp Use SmallVectorImpl& instead of SmallVector to avoid repeating small vector size. 2013-07-14 04:42:23 +00:00
SimplifyCFGPass.cpp Reapply r188119 now that the bug it exposed is fixed. 2013-08-12 22:38:43 +00:00
Sink.cpp Move all of the header files which are involved in modelling the LLVM IR 2013-01-02 11:36:10 +00:00
SROA.cpp Drop spurious handle in comment. 2013-09-22 11:24:58 +00:00
StructurizeCFG.cpp StructurizeCFG: Add dependency on LowerSwitch pass 2013-10-02 17:04:59 +00:00
TailRecursionElimination.cpp TRE: Move class into anonymous namespace. 2013-07-24 16:12:08 +00:00