[NFC] Reuse existing variables instead of re-requesting successors

This commit is contained in:
Max Kazantsev 2021-05-27 15:01:20 +07:00
parent 9f39ba13b5
commit c467585682
1 changed files with 5 additions and 6 deletions

View File

@ -293,7 +293,7 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
using namespace PatternMatch; using namespace PatternMatch;
ICmpInst::Predicate Pred; ICmpInst::Predicate Pred;
Value *LHS, *RHS; Value *LHS, *RHS;
const BasicBlock *IfTrue, *IfFalse; BasicBlock *IfTrue, *IfFalse;
auto *Term = BB->getTerminator(); auto *Term = BB->getTerminator();
// TODO: Handle switches. // TODO: Handle switches.
if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)), if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
@ -316,13 +316,12 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
// in-loop. // in-loop.
// TODO: isKnownPredicateAt is more powerful, but it's too compile time // TODO: isKnownPredicateAt is more powerful, but it's too compile time
// consuming. So we avoid using it here. // consuming. So we avoid using it here.
if (L->contains(Term->getSuccessor(1)) && if (L->contains(IfFalse) && SE.isKnownPredicate(Pred, LHSS, RHSS))
SE.isKnownPredicate(Pred, LHSS, RHSS)) MarkLiveEdge(BB, IfTrue);
MarkLiveEdge(BB, Term->getSuccessor(0)); else if (L->contains(IfTrue) &&
else if (L->contains(Term->getSuccessor(0)) &&
SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS, SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS,
RHSS)) RHSS))
MarkLiveEdge(BB, Term->getSuccessor(1)); MarkLiveEdge(BB, IfFalse);
else else
MarkAllSuccessorsLive(BB); MarkAllSuccessorsLive(BB);
} }