From a44b7322a27a636da6a6e1a28091dc7a6d59a4be Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 3 Nov 2020 14:13:28 +0700 Subject: [PATCH] [NFC] Split lambda into 2 parts for further reuse --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 0ee0d6e..650e049 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -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(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; -- 2.7.4