[NFCI][LoopDeletion] Only query SCEV about loop successor if another successor is also in loop

This commit is contained in:
Max Kazantsev 2021-05-27 11:47:30 +07:00
parent d82f2a123f
commit b0b2bf3b5d
1 changed files with 13 additions and 10 deletions

View File

@ -267,10 +267,10 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
ICmpInst::Predicate Pred; ICmpInst::Predicate Pred;
Value *LHS, *RHS; Value *LHS, *RHS;
const BasicBlock *IfTrue, *IfFalse; const BasicBlock *IfTrue, *IfFalse;
auto *Term = BB->getTerminator();
// TODO: Handle switches. // TODO: Handle switches.
if (!match(BB->getTerminator(), if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)), m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
m_BasicBlock(IfTrue), m_BasicBlock(IfFalse)))) {
MarkAllSuccessorsLive(BB); MarkAllSuccessorsLive(BB);
continue; continue;
} }
@ -283,13 +283,16 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
// Can we prove constant true or false for this condition? // Can we prove constant true or false for this condition?
const SCEV *LHSS = getSCEVOnFirstIteration(LHS, L, SE, FirstIterSCEV); const SCEV *LHSS = getSCEVOnFirstIteration(LHS, L, SE, FirstIterSCEV);
const SCEV *RHSS = getSCEVOnFirstIteration(RHS, L, SE, FirstIterSCEV); const SCEV *RHSS = getSCEVOnFirstIteration(RHS, L, SE, FirstIterSCEV);
// TODO: isKnownPredicateAt is more powerful, but it's too compile time // Only query for liveness of in-loop edge if another successor is also
// consuming. So we avoid using it here. // in-loop.
if (SE.isKnownPredicate(Pred, LHSS, RHSS)) // TODO: isKnownPredicateAt is more powerful, but it's too compile time
MarkLiveEdge(BB, BB->getTerminator()->getSuccessor(0)); // consuming. So we avoid using it here.
else if (SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS, if (L->contains(Term->getSuccessor(1)) &&
RHSS)) SE.isKnownPredicate(Pred, LHSS, RHSS))
MarkLiveEdge(BB, BB->getTerminator()->getSuccessor(1)); MarkLiveEdge(BB, Term->getSuccessor(0));
else if (L->contains(Term->getSuccessor(0)) &&
SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS,
RHSS)) MarkLiveEdge(BB, Term->getSuccessor(1));
else else
MarkAllSuccessorsLive(BB); MarkAllSuccessorsLive(BB);
} }