[llvm] r332004 - [PM/LoopUnswitch] Avoid pointlessly creating an exit block set.
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Thu May 10 10:33:20 PDT 2018
Author: chandlerc
Date: Thu May 10 10:33:20 2018
New Revision: 332004
URL: http://llvm.org/viewvc/llvm-project?rev=332004&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp?rev=332004&r1=332003&r2=332004&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp Thu May 10 10:33:20 2018
@@ -192,12 +192,6 @@ static bool unswitchTrivialBranch(Loop &
if (!L.isLoopInvariant(LoopCond))
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
// exit through a unique exit block without having any
// side-effects. If so, determine the value of Cond that causes
@@ -206,17 +200,14 @@ static bool unswitchTrivialBranch(Loop &
ConstantInt *Replacement = ConstantInt::getFalse(BI.getContext());
int LoopExitSuccIdx = 0;
auto *LoopExitBB = BI.getSuccessor(0);
- if (!ExitBlockSet.count(LoopExitBB)) {
+ if (L.contains(LoopExitBB)) {
std::swap(CondVal, Replacement);
LoopExitSuccIdx = 1;
LoopExitBB = BI.getSuccessor(1);
- if (!ExitBlockSet.count(LoopExitBB))
+ if (L.contains(LoopExitBB))
return false;
}
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();
if (!areLoopExitPHIsLoopInvariant(L, *ParentBB, *LoopExitBB))
return false;
@@ -310,21 +301,15 @@ static bool unswitchTrivialSwitch(Loop &
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;
for (auto Case : SI.cases()) {
auto *SuccBB = Case.getCaseSuccessor();
- if (ExitBlockSet.count(SuccBB) &&
+ if (!L.contains(SuccBB) &&
areLoopExitPHIsLoopInvariant(L, *ParentBB, *SuccBB))
ExitCaseIndices.push_back(Case.getCaseIndex());
}
BasicBlock *DefaultExitBB = nullptr;
- if (ExitBlockSet.count(SI.getDefaultDest()) &&
+ if (!L.contains(SI.getDefaultDest()) &&
areLoopExitPHIsLoopInvariant(L, *ParentBB, *SI.getDefaultDest()) &&
!isa<UnreachableInst>(SI.getDefaultDest()->getTerminator()))
DefaultExitBB = SI.getDefaultDest();
More information about the llvm-commits
mailing list