aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index c235d2fb2a5b..4f7956514b7b 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -770,8 +770,7 @@ static bool unswitchTrivialSwitch(Loop &L, SwitchInst &SI, DominatorTree &DT,
// instruction in the block.
auto *TI = BBToCheck.getTerminator();
bool isUnreachable = isa<UnreachableInst>(TI);
- return !isUnreachable ||
- (isUnreachable && (BBToCheck.getFirstNonPHIOrDbg() != TI));
+ return !isUnreachable || &*BBToCheck.getFirstNonPHIOrDbg() != TI;
};
SmallVector<int, 4> ExitCaseIndices;
@@ -1249,8 +1248,9 @@ static BasicBlock *buildClonedLoopBlocks(
assert(VMap.lookup(&I) == &ClonedI && "Mismatch in the value map!");
// Forget SCEVs based on exit phis in case SCEV looked through the phi.
- if (SE && isa<PHINode>(I))
- SE->forgetValue(&I);
+ if (SE)
+ if (auto *PN = dyn_cast<PHINode>(&I))
+ SE->forgetLcssaPhiWithNewPredecessor(&L, PN);
BasicBlock::iterator InsertPt = MergeBB->getFirstInsertionPt();
@@ -2786,7 +2786,7 @@ static BranchInst *turnGuardIntoBranch(IntrinsicInst *GI, Loop &L,
if (MSSAU)
MSSAU->moveAllAfterSpliceBlocks(CheckBB, GuardedBlock, GI);
- GI->moveBefore(DeoptBlockTerm);
+ GI->moveBefore(DeoptBlockTerm->getIterator());
GI->setArgOperand(0, ConstantInt::getFalse(GI->getContext()));
if (MSSAU) {
@@ -2921,8 +2921,8 @@ static bool collectUnswitchCandidates(
// Whether or not we should also collect guards in the loop.
bool CollectGuards = false;
if (UnswitchGuards) {
- auto *GuardDecl = L.getHeader()->getParent()->getParent()->getFunction(
- Intrinsic::getName(Intrinsic::experimental_guard));
+ auto *GuardDecl = Intrinsic::getDeclarationIfExists(
+ L.getHeader()->getParent()->getParent(), Intrinsic::experimental_guard);
if (GuardDecl && !GuardDecl->use_empty())
CollectGuards = true;
}
@@ -2990,9 +2990,11 @@ static bool collectUnswitchCandidates(
/// into its equivalent where `Pred` is something that we support for injected
/// invariants (so far it is limited to ult), LHS in canonicalized form is
/// non-invariant and RHS is an invariant.
-static void canonicalizeForInvariantConditionInjection(
- ICmpInst::Predicate &Pred, Value *&LHS, Value *&RHS, BasicBlock *&IfTrue,
- BasicBlock *&IfFalse, const Loop &L) {
+static void canonicalizeForInvariantConditionInjection(CmpPredicate &Pred,
+ Value *&LHS, Value *&RHS,
+ BasicBlock *&IfTrue,
+ BasicBlock *&IfFalse,
+ const Loop &L) {
if (!L.contains(IfTrue)) {
Pred = ICmpInst::getInversePredicate(Pred);
std::swap(IfTrue, IfFalse);
@@ -3235,7 +3237,7 @@ static bool collectUnswitchCandidatesWithInjections(
// other).
for (auto *DTN = DT.getNode(Latch); L.contains(DTN->getBlock());
DTN = DTN->getIDom()) {
- ICmpInst::Predicate Pred;
+ CmpPredicate Pred;
Value *LHS = nullptr, *RHS = nullptr;
BasicBlock *IfTrue = nullptr, *IfFalse = nullptr;
auto *BB = DTN->getBlock();
@@ -3301,8 +3303,8 @@ static bool isSafeForNoNTrivialUnswitching(Loop &L, LoopInfo &LI) {
// FIXME: We should teach SplitBlock to handle this and remove this
// restriction.
for (auto *ExitBB : ExitBlocks) {
- auto *I = ExitBB->getFirstNonPHI();
- if (isa<CleanupPadInst>(I) || isa<CatchSwitchInst>(I)) {
+ auto It = ExitBB->getFirstNonPHIIt();
+ if (isa<CleanupPadInst>(It) || isa<CatchSwitchInst>(It)) {
LLVM_DEBUG(dbgs() << "Cannot unswitch because of cleanuppad/catchswitch "
"in exit block\n");
return false;