[SCEV][NFC][CT] Do not waste time proving contextual facts for unreached loops and blocks

In fact, in unreached code we can say that every fact is true. So do not waste time trying to
do something smarter.

Formally it's not an NFC because it may change query results in unreached code, but they
won't have any impact on execution.

Hypothetical CT boost expected but not measured in practice.

Differential Revision: https://reviews.llvm.org/D129878
This commit is contained in:
Max Kazantsev 2022-07-20 19:01:43 +07:00
parent 7af2818a99
commit e0ccd190ae
1 changed files with 7 additions and 8 deletions

View File

@ -11012,8 +11012,10 @@ ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
ICmpInst::Predicate Pred, ICmpInst::Predicate Pred,
const SCEV *LHS, const SCEV *RHS) { const SCEV *LHS, const SCEV *RHS) {
// Interpret a null as meaning no loop, where there is obviously no guard // Interpret a null as meaning no loop, where there is obviously no guard
// (interprocedural conditions notwithstanding). // (interprocedural conditions notwithstanding). Do not bother about
if (!L) return true; // unreachable loops.
if (!L || !DT.isReachableFromEntry(L->getHeader()))
return true;
if (VerifyIR) if (VerifyIR)
assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) && assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) &&
@ -11070,12 +11072,6 @@ ScalarEvolution::isLoopBackedgeGuardedByCond(const Loop *L,
return true; return true;
} }
// If the loop is not reachable from the entry block, we risk running into an
// infinite loop as we walk up into the dom tree. These loops do not matter
// anyway, so we just return a conservative answer when we see them.
if (!DT.isReachableFromEntry(L->getHeader()))
return false;
if (isImpliedViaGuard(Latch, Pred, LHS, RHS)) if (isImpliedViaGuard(Latch, Pred, LHS, RHS))
return true; return true;
@ -11121,6 +11117,9 @@ bool ScalarEvolution::isBasicBlockEntryGuardedByCond(const BasicBlock *BB,
ICmpInst::Predicate Pred, ICmpInst::Predicate Pred,
const SCEV *LHS, const SCEV *LHS,
const SCEV *RHS) { const SCEV *RHS) {
// Do not bother proving facts for unreachable code.
if (!DT.isReachableFromEntry(BB))
return true;
if (VerifyIR) if (VerifyIR)
assert(!verifyFunction(*BB->getParent(), &dbgs()) && assert(!verifyFunction(*BB->getParent(), &dbgs()) &&
"This cannot be done on broken IR!"); "This cannot be done on broken IR!");