forked from OSchip/llvm-project
[SCEV][NFC][CT] Cheaper handling of guards in isBasicBlockEntryGuardedByCond
Handle guards uniformly with assumes, rather than iterating through all block instructions in attempt to find them. Differential Revision: https://reviews.llvm.org/D129874 Reviewed By: nikic
This commit is contained in:
parent
9d5a544d34
commit
a053f35990
|
@ -11153,20 +11153,6 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to prove (Pred, LHS, RHS) using isImpliedViaGuard.
|
|
||||||
auto ProveViaGuard = [&](const BasicBlock *Block) {
|
|
||||||
if (isImpliedViaGuard(Block, Pred, LHS, RHS))
|
|
||||||
return true;
|
|
||||||
if (ProvingStrictComparison) {
|
|
||||||
auto ProofFn = [&](ICmpInst::Predicate P) {
|
|
||||||
return isImpliedViaGuard(Block, P, LHS, RHS);
|
|
||||||
};
|
|
||||||
if (SplitAndProve(ProofFn))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Try to prove (Pred, LHS, RHS) using isImpliedCond.
|
// Try to prove (Pred, LHS, RHS) using isImpliedCond.
|
||||||
auto ProveViaCond = [&](const Value *Condition, bool Inverse) {
|
auto ProveViaCond = [&](const Value *Condition, bool Inverse) {
|
||||||
const Instruction *CtxI = &BB->front();
|
const Instruction *CtxI = &BB->front();
|
||||||
|
@ -11193,9 +11179,6 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
|
||||||
PredBB = BB->getSinglePredecessor();
|
PredBB = BB->getSinglePredecessor();
|
||||||
for (std::pair<const BasicBlock *, const BasicBlock *> Pair(PredBB, BB);
|
for (std::pair<const BasicBlock *, const BasicBlock *> Pair(PredBB, BB);
|
||||||
Pair.first; Pair = getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
|
Pair.first; Pair = getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
|
||||||
if (ProveViaGuard(Pair.first))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
const BranchInst *BlockEntryPredicate =
|
const BranchInst *BlockEntryPredicate =
|
||||||
dyn_cast<BranchInst>(Pair.first->getTerminator());
|
dyn_cast<BranchInst>(Pair.first->getTerminator());
|
||||||
if (!BlockEntryPredicate || BlockEntryPredicate->isUnconditional())
|
if (!BlockEntryPredicate || BlockEntryPredicate->isUnconditional())
|
||||||
|
@ -11218,6 +11201,15 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check conditions due to any @llvm.experimental.guard intrinsics.
|
||||||
|
auto *GuardDecl = F.getParent()->getFunction(
|
||||||
|
Intrinsic::getName(Intrinsic::experimental_guard));
|
||||||
|
if (GuardDecl)
|
||||||
|
for (const auto *GU : GuardDecl->users())
|
||||||
|
if (const auto *Guard = dyn_cast<IntrinsicInst>(GU))
|
||||||
|
if (Guard->getFunction() == BB->getParent() && DT.dominates(Guard, BB))
|
||||||
|
if (ProveViaCond(Guard->getArgOperand(0), false))
|
||||||
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue