summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMichael Kuperstein <mkuper@google.com>2016-12-29 23:11:19 +0000
committerMichael Kuperstein <mkuper@google.com>2016-12-29 23:11:19 +0000
commitff36baefe7800283997f418aa22471890317c748 (patch)
tree7ba9bca56764805b988fe87b8f16b5185c12e314 /llvm
parent556609296341c2a09fe650c2a1102d0d89458f75 (diff)
downloadbcm5719-llvm-ff36baefe7800283997f418aa22471890317c748.tar.gz
bcm5719-llvm-ff36baefe7800283997f418aa22471890317c748.zip
[LICM] Compute exit blocks for promotion eagerly. NFC.
This moves the exit block and insertion point computation to be eager, instead of after seeing the first scalar we can promote. The cost is relatively small (the computation happens anyway, see discussion on D28147), and the code is easier to follow, and can bail out earlier if there's a catchswitch present. llvm-svn: 290729
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Scalar/LICM.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 79dc103a774..4c05f42fe0e 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -256,27 +256,42 @@ bool LoopInvariantCodeMotion::runOnLoop(Loop *L, AliasAnalysis *AA,
// preheader for SSA updater, so also avoid sinking when no preheader
// is available.
if (!DisablePromotion && Preheader && L->hasDedicatedExits()) {
+ // Figure out the loop exits and their insertion points
SmallVector<BasicBlock *, 8> ExitBlocks;
- SmallVector<Instruction *, 8> InsertPts;
- PredIteratorCache PIC;
-
- bool Promoted = false;
-
- // Loop over all of the alias sets in the tracker object.
- for (AliasSet &AS : *CurAST)
- Promoted |= promoteLoopAccessesToScalars(
- AS, ExitBlocks, InsertPts, PIC, LI, DT, TLI, L, CurAST, &SafetyInfo);
-
- // Once we have promoted values across the loop body we have to recursively
- // reform LCSSA as any nested loop may now have values defined within the
- // loop used in the outer loop.
- // FIXME: This is really heavy handed. It would be a bit better to use an
- // SSAUpdater strategy during promotion that was LCSSA aware and reformed
- // it as it went.
- if (Promoted)
- formLCSSARecursively(*L, *DT, LI, SE);
-
- Changed |= Promoted;
+ L->getUniqueExitBlocks(ExitBlocks);
+
+ // We can't insert into a catchswitch.
+ bool HasCatchSwitch = llvm::any_of(ExitBlocks, [](BasicBlock *Exit) {
+ return isa<CatchSwitchInst>(Exit->getTerminator());
+ });
+
+ if (!HasCatchSwitch) {
+ SmallVector<Instruction *, 8> InsertPts;
+ InsertPts.reserve(ExitBlocks.size());
+ for (BasicBlock *ExitBlock : ExitBlocks)
+ InsertPts.push_back(&*ExitBlock->getFirstInsertionPt());
+
+ PredIteratorCache PIC;
+
+ bool Promoted = false;
+
+ // Loop over all of the alias sets in the tracker object.
+ for (AliasSet &AS : *CurAST)
+ Promoted |=
+ promoteLoopAccessesToScalars(AS, ExitBlocks, InsertPts, PIC, LI, DT,
+ TLI, L, CurAST, &SafetyInfo);
+
+ // Once we have promoted values across the loop body we have to
+ // recursively reform LCSSA as any nested loop may now have values defined
+ // within the loop used in the outer loop.
+ // FIXME: This is really heavy handed. It would be a bit better to use an
+ // SSAUpdater strategy during promotion that was LCSSA aware and reformed
+ // it as it went.
+ if (Promoted)
+ formLCSSARecursively(*L, *DT, LI, SE);
+
+ Changed |= Promoted;
+ }
}
// Check that neither this loop nor its parent have had LCSSA broken. LICM is
@@ -1016,24 +1031,10 @@ bool llvm::promoteLoopAccessesToScalars(
PromotionIsLegal =
isAllocLikeFn(Object, TLI) && !PointerMayBeCaptured(Object, true, true);
}
+
if (!PromotionIsLegal)
return Changed;
- // Figure out the loop exits and their insertion points, if this is the
- // first promotion.
- if (ExitBlocks.empty()) {
- CurLoop->getUniqueExitBlocks(ExitBlocks);
- InsertPts.clear();
- InsertPts.reserve(ExitBlocks.size());
- for (BasicBlock *ExitBlock : ExitBlocks)
- InsertPts.push_back(&*ExitBlock->getFirstInsertionPt());
- }
-
- // Can't insert into a catchswitch.
- for (BasicBlock *ExitBlock : ExitBlocks)
- if (isa<CatchSwitchInst>(ExitBlock->getTerminator()))
- return Changed;
-
// Otherwise, this is safe to promote, lets do it!
DEBUG(dbgs() << "LICM: Promoting value stored to in loop: " << *SomePtr
<< '\n');
OpenPOWER on IntegriCloud