summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Trick <atrick@apple.com>2011-09-29 01:33:38 +0000
committerAndrew Trick <atrick@apple.com>2011-09-29 01:33:38 +0000
commit0c01bc385a4c01bee012bda504c8ce0c3d402f2c (patch)
tree9b57d78a2b2d96043cf7ca24139ac4080e413fee /lib
parent03b08764d2d1735c33710950be4207edc9b90fb2 (diff)
downloadllvm-0c01bc385a4c01bee012bda504c8ce0c3d402f2c.tar.gz
llvm-0c01bc385a4c01bee012bda504c8ce0c3d402f2c.tar.bz2
llvm-0c01bc385a4c01bee012bda504c8ce0c3d402f2c.tar.xz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index f9c18c8ae2..49228a88cd 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -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();