LSR: rewrite inner loops only.

Rewriting the entire loop nest now requires -enable-lsr-nested.
See PR11035 for some performance data.
A few unit tests specifically test nested LSR, and are now under a flag.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Andrew Trick
2011-09-29 01:33:38 +00:00
parent 03b08764d2
commit 0c01bc385a
7 changed files with 45 additions and 14 deletions

View File

@ -78,6 +78,9 @@
using namespace llvm;
namespace llvm {
cl::opt<bool> EnableNested(
"enable-lsr-nested", cl::Hidden, cl::desc("Enable LSR on nested loops"));
cl::opt<bool> EnableRetry(
"enable-lsr-retry", cl::Hidden, cl::desc("Enable LSR retry"));
}
@ -723,11 +726,14 @@ void Cost::RateRegister(const SCEV *Reg,
if (AR->getLoop() == L)
AddRecCost += 1; /// TODO: This should be a function of the stride.
// If this is an addrec for a loop that's already been visited by LSR,
// don't second-guess its addrec phi nodes. LSR isn't currently smart
// enough to reason about more than one loop at a time. Consider these
// registers free and leave them alone.
else if (L->contains(AR->getLoop()) ||
// If this is an addrec for another loop, don't second-guess its addrec phi
// nodes. LSR isn't currently smart enough to reason about more than one
// loop at a time. LSR has either already run on inner loops, will not run
// on other loops, and cannot be expected to change sibling loops. If the
// AddRec exists, consider it's register free and leave it alone. Otherwise,
// do not consider this formula at all.
// FIXME: why do we need to generate such fomulae?
else if (!EnableNested || L->contains(AR->getLoop()) ||
(!AR->getLoop()->contains(L) &&
DT.dominates(L->getHeader(), AR->getLoop()->getHeader()))) {
for (BasicBlock::iterator I = AR->getLoop()->getHeader()->begin();
@ -738,6 +744,10 @@ void Cost::RateRegister(const SCEV *Reg,
SE.getSCEV(PN) == AR)
return;
}
if (!EnableNested) {
Loose();
return;
}
// If this isn't one of the addrecs that the loop already has, it
// would require a costly new phi and add. TODO: This isn't
// precisely modeled right now.
@ -3801,6 +3811,12 @@ LSRInstance::LSRInstance(const TargetLowering *tli, Loop *l, Pass *P)
// If loop preparation eliminates all interesting IV users, bail.
if (IU.empty()) return;
// Skip nested loops until we can model them better with forulae.
if (!EnableNested && !L->empty()) {
DEBUG(dbgs() << "LSR skipping outer loop " << *L << "\n");
return false;
}
// Start collecting data and preparing for the solver.
CollectInterestingTypesAndFactors();
CollectFixupsAndInitialFormulae();