1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[PM/LoopUnswitch] Avoid pointlessly creating an exit block set.

This code can just test whether blocks are *in* the loop, which we
already have a dedicated set tracking in the loop itself.

llvm-svn: 332004
This commit is contained in:
Chandler Carruth 2018-05-10 17:33:20 +00:00
parent f555f6990b
commit 2c136062f2

View File

@ -192,12 +192,6 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
if (!L.isLoopInvariant(LoopCond)) if (!L.isLoopInvariant(LoopCond))
return false; return false;
// FIXME: We should compute this once at the start and update it!
SmallVector<BasicBlock *, 16> ExitBlocks;
L.getExitBlocks(ExitBlocks);
SmallPtrSet<BasicBlock *, 16> ExitBlockSet(ExitBlocks.begin(),
ExitBlocks.end());
// Check to see if a successor of the branch is guaranteed to // Check to see if a successor of the branch is guaranteed to
// exit through a unique exit block without having any // exit through a unique exit block without having any
// side-effects. If so, determine the value of Cond that causes // side-effects. If so, determine the value of Cond that causes
@ -206,17 +200,14 @@ static bool unswitchTrivialBranch(Loop &L, BranchInst &BI, DominatorTree &DT,
ConstantInt *Replacement = ConstantInt::getFalse(BI.getContext()); ConstantInt *Replacement = ConstantInt::getFalse(BI.getContext());
int LoopExitSuccIdx = 0; int LoopExitSuccIdx = 0;
auto *LoopExitBB = BI.getSuccessor(0); auto *LoopExitBB = BI.getSuccessor(0);
if (!ExitBlockSet.count(LoopExitBB)) { if (L.contains(LoopExitBB)) {
std::swap(CondVal, Replacement); std::swap(CondVal, Replacement);
LoopExitSuccIdx = 1; LoopExitSuccIdx = 1;
LoopExitBB = BI.getSuccessor(1); LoopExitBB = BI.getSuccessor(1);
if (!ExitBlockSet.count(LoopExitBB)) if (L.contains(LoopExitBB))
return false; return false;
} }
auto *ContinueBB = BI.getSuccessor(1 - LoopExitSuccIdx); auto *ContinueBB = BI.getSuccessor(1 - LoopExitSuccIdx);
assert(L.contains(ContinueBB) &&
"Cannot have both successors exit and still be in the loop!");
auto *ParentBB = BI.getParent(); auto *ParentBB = BI.getParent();
if (!areLoopExitPHIsLoopInvariant(L, *ParentBB, *LoopExitBB)) if (!areLoopExitPHIsLoopInvariant(L, *ParentBB, *LoopExitBB))
return false; return false;
@ -310,21 +301,15 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
auto *ParentBB = SI.getParent(); auto *ParentBB = SI.getParent();
// FIXME: We should compute this once at the start and update it!
SmallVector<BasicBlock *, 16> ExitBlocks;
L.getExitBlocks(ExitBlocks);
SmallPtrSet<BasicBlock *, 16> ExitBlockSet(ExitBlocks.begin(),
ExitBlocks.end());
SmallVector<int, 4> ExitCaseIndices; SmallVector<int, 4> ExitCaseIndices;
for (auto Case : SI.cases()) { for (auto Case : SI.cases()) {
auto *SuccBB = Case.getCaseSuccessor(); auto *SuccBB = Case.getCaseSuccessor();
if (ExitBlockSet.count(SuccBB) && if (!L.contains(SuccBB) &&
areLoopExitPHIsLoopInvariant(L, *ParentBB, *SuccBB)) areLoopExitPHIsLoopInvariant(L, *ParentBB, *SuccBB))
ExitCaseIndices.push_back(Case.getCaseIndex()); ExitCaseIndices.push_back(Case.getCaseIndex());
} }
BasicBlock *DefaultExitBB = nullptr; BasicBlock *DefaultExitBB = nullptr;
if (ExitBlockSet.count(SI.getDefaultDest()) && if (!L.contains(SI.getDefaultDest()) &&
areLoopExitPHIsLoopInvariant(L, *ParentBB, *SI.getDefaultDest()) && areLoopExitPHIsLoopInvariant(L, *ParentBB, *SI.getDefaultDest()) &&
!isa<UnreachableInst>(SI.getDefaultDest()->getTerminator())) !isa<UnreachableInst>(SI.getDefaultDest()->getTerminator()))
DefaultExitBB = SI.getDefaultDest(); DefaultExitBB = SI.getDefaultDest();