[NFC] Split lambda into 2 parts for further reuse

This commit is contained in:
Max Kazantsev 2020-11-03 14:13:28 +07:00
parent 46e91f6701
commit a44b7322a2
1 changed files with 8 additions and 3 deletions

View File

@ -2406,15 +2406,20 @@ bool IndVarSimplify::optimizeLoopExits(Loop *L, SCEVExpander &Rewriter) {
}
#endif
auto ReplaceExitCond = [&](BranchInst *BI, Value *NewCond) {
auto *OldCond = BI->getCondition();
BI->setCondition(NewCond);
if (OldCond->use_empty())
DeadInsts.emplace_back(OldCond);
};
auto FoldExit = [&](BasicBlock *ExitingBB, bool IsTaken) {
BranchInst *BI = cast<BranchInst>(ExitingBB->getTerminator());
bool ExitIfTrue = !L->contains(*succ_begin(ExitingBB));
auto *OldCond = BI->getCondition();
auto *NewCond = ConstantInt::get(OldCond->getType(),
IsTaken ? ExitIfTrue : !ExitIfTrue);
BI->setCondition(NewCond);
if (OldCond->use_empty())
DeadInsts.emplace_back(OldCond);
ReplaceExitCond(BI, NewCond);
};
bool Changed = false;