summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorMichael Zolotukhin <mzolotukhin@apple.com>2016-06-10 22:03:56 +0000
committerMichael Zolotukhin <mzolotukhin@apple.com>2016-06-10 22:03:56 +0000
commitb98294d006c97d5f7908e9b24f4fcf28b3195564 (patch)
tree9828468e0d3ffd4fe9720dff3caca7ee77e804a8 /llvm/lib/Transforms/Scalar
parente5d2d71a60fbe4cddcb7a070f0eed1648b3d40c6 (diff)
downloadbcm5719-llvm-b98294d006c97d5f7908e9b24f4fcf28b3195564.tar.gz
bcm5719-llvm-b98294d006c97d5f7908e9b24f4fcf28b3195564.zip
Don't try to rotate a loop more than once - we never do this anyway.
Summary: I can't find a case where we can rotate a loop more than once, and it looks like we never do this. To rotate a loop following conditions should be met: 1) its header should be exiting 2) its latch shouldn't be exiting But after the first rotation the header becomes the new latch, so this condition can never be true any longer. Tested on with an assert on LNT testsuite and make check. Reviewers: hfinkel, sanjoy Subscribers: sebpop, sanjoy, llvm-commits, mzolotukhin Differential Revision: http://reviews.llvm.org/D20181 llvm-svn: 272439
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopRotation.cpp24
1 files changed, 10 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopRotation.cpp b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
index a27a314cac5..82de322ab11 100644
--- a/llvm/lib/Transforms/Scalar/LoopRotation.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopRotation.cpp
@@ -569,12 +569,10 @@ static bool simplifyLoopLatch(Loop *L, LoopInfo *LI, DominatorTree *DT) {
return true;
}
-/// Rotate \c L as many times as possible. Return true if the loop is rotated
-/// at least once.
-static bool iterativelyRotateLoop(Loop *L, unsigned MaxHeaderSize, LoopInfo *LI,
- const TargetTransformInfo *TTI,
- AssumptionCache *AC, DominatorTree *DT,
- ScalarEvolution *SE) {
+/// Rotate \c L, and return true if any modification was made.
+static bool processLoop(Loop *L, unsigned MaxHeaderSize, LoopInfo *LI,
+ const TargetTransformInfo *TTI, AssumptionCache *AC,
+ DominatorTree *DT, ScalarEvolution *SE) {
// Save the loop metadata.
MDNode *LoopMD = L->getLoopID();
@@ -583,12 +581,10 @@ static bool iterativelyRotateLoop(Loop *L, unsigned MaxHeaderSize, LoopInfo *LI,
// loop exit.
bool SimplifiedLatch = simplifyLoopLatch(L, LI, DT);
- // One loop can be rotated multiple times.
- bool MadeChange = false;
- while (rotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE, SimplifiedLatch)) {
- MadeChange = true;
- SimplifiedLatch = false;
- }
+ bool MadeChange =
+ rotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE, SimplifiedLatch);
+ assert((!MadeChange || L->isLoopExiting(L->getLoopLatch())) &&
+ "Loop latch should be exiting after loop-rotate.");
// Restore the loop metadata.
// NB! We presume LoopRotation DOESN'T ADD its own metadata.
@@ -613,7 +609,7 @@ PreservedAnalyses LoopRotatePass::run(Loop &L, AnalysisManager<Loop> &AM) {
auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
- bool Changed = iterativelyRotateLoop(&L, MaxHeaderSize, LI, TTI, AC, DT, SE);
+ bool Changed = processLoop(&L, MaxHeaderSize, LI, TTI, AC, DT, SE);
if (!Changed)
return PreservedAnalyses::all();
return getLoopPassPreservedAnalyses();
@@ -654,7 +650,7 @@ public:
auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
auto *SE = SEWP ? &SEWP->getSE() : nullptr;
- return iterativelyRotateLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE);
+ return processLoop(L, MaxHeaderSize, LI, TTI, AC, DT, SE);
}
};
}
OpenPOWER on IntegriCloud